Skip to content Skip to sidebar Skip to footer

How Can I Search Multiple Columns In Datatables?

I am trying to combine a column search and a normal search on specific columns. If you look for example at the snippet below, I want to be able to search the columns Name and Posit

Solution 1:

You can override the built in search / filter with a custom filter :

$('.dataTables_filter input').unbind().on('keyup', function() {
    var searchTerm = this.value.toLowerCase();
    $.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
       //search only in column 1 and 2if (~data[0].toLowerCase().indexOf(searchTerm)) returntrue;
       if (~data[1].toLowerCase().indexOf(searchTerm)) returntrue;
       returnfalse;
   })
   table.draw(); 
   $.fn.dataTable.ext.search.pop();
})

By this the "normal search" only applies to the first two columns, Name and Position - and you still have working select boxes in the footer. Forked fiddle -> https://jsfiddle.net/g9gLjtjh/

Post a Comment for "How Can I Search Multiple Columns In Datatables?"