jjjjjj jjjjjj - 1 year ago 112
AngularJS Question

AngularJs + angular datatable

Anyone here using angular-datatables in AngularJS?

Edited: I want to filter data in my table. In specific. like if the select is about category. It will only filter what's in the category column. But in my filter as of now. It filters everything.

Here is my code for filtering select. I just copy how the "search box" filtered the data. because I don't know the correct code for filtering using select. and It is customized.

function dtInstanceCallback (dtInstance) {
var datatableObj = dtInstance.DataTable;
vm.tableInstance = datatableObj;

function searchTable () {
var query = vm.queryProductSearch;

function selectCategoryInTable () {
var sel = vm.selCategory;

function selectStatusInTable () {
var sel = vm.selStatus;

the searchTable() is for my search box. and selectCategoryInTable / selectStatusInTable is for my category column and status column in my table. But it filters everything.

And I want to know how to filter specific data. Like if I filter "ACTIVE". my data in datatable will show "INACTIVE" too because there's "ACTIVE" in "INACTIVE". so I want to filter specific word.

Answer Source

It does not seem right. The correct usage of dataTables 1.10.x API from a dtInstance would be


if you want to search within a particular column, you can use


if you want to search for whole words, and not just part of words (like active vs inactive) then use a regular expression search. Wrap query into ^..$ and set first param to true, see docs for search() :

vm.tableInstance.DataTable.column(1).search('^'+query+'$', true).draw()

here is an example searching for foo in column #1 -> http://plnkr.co/edit/s1pP42YFE4WeuStdaK8d?p=preview

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download