Reputation: 303
I want a filtering in my datatable MS-crm-like (contains, does not contain, begins with, greater than....) for every column.
I've tried it the way as it was explained in this example: http://legacy.datatables.net/release-datatables/examples/plug-ins/range_filtering.html
the problem is that this filter only works for current column (for one column), so if I filter for column A and afterwards I want to filter for column B too, the filter of column A is obsolate.
Everytime I call oTable.draw()
it will be refiltered for the current column.
What do I miss?
Upvotes: 1
Views: 2847
Reputation: 58890
Your example is for older version of jQuery DataTables. See this example for the current version.
Treat $.fn.dataTableExt.afnFiltering
(or $.fn.dataTable.ext.search
) as array of functions. Reset the array first, add as many functions as you need and then call draw()
API method.
For example:
var table = $('#example').DataTable();
// Handle click on "Search" button
$('#btn-search').on('click', function(){
// Reset custom search
$.fn.dataTable.ext.search = [];
// Add search criteria for column 1
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ){
// ... skipped ...
return (success) ? true : false;
}
);
// Add search criteria for column 2
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ){
// ... skipped ...
return (success) ? true : false;
}
);
// Perform the search
table.draw();
});
Upvotes: 3