How can I search multiple columns in DataTables?

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 2
       if (~data[0].toLowerCase().indexOf(searchTerm)) return true;
       if (~data[1].toLowerCase().indexOf(searchTerm)) return true;
       return false;
   })
   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/

Leave a Comment