Custom filtering in multiple tables

Custom filtering in multiple tables

fatema_bornafatema_borna Posts: 2Questions: 1Answers: 0

am using datatables. i want that two datatables will use same custom filtering function.filter style will be when i write in global search box it will show data that start with that searching word suppose i write 'b' in search box then it will show 'brain','break','bye' etc that's start with 'b'. am already found a function which seaching that start with that search word.the problem is that when i try to use two data tables. one datatable works properly but other datatable tbody datas is not shown. my code below that i used.

$.fn.dataTableExt.afnFiltering.push(function( oSettings, aData, iDataIndex ) {
if(oSettings.oInit.bCustomFilter){
console.log("YES!");// do whatever and return true or false

var keywords = $(".dataTables_filter input").val().split(' ');
var matches = 0;
for (var k=0; k<keywords.length; k++) {
var keyword = keywords[k];
for (var col=0; col<aData.length; col++) {
if (aData[col].charAt(0).toLowerCase() == keyword.charAt(0).toLowerCase()) {
matches++;
break;
}
}
}
return matches == keywords.length;
}

}else //return true because we don't want it filtered out
return true;
});

$('#table1').dataTable({ "bCustomFilter":true});
$('#table2').dataTable({ "bCustomFilter":true});

Answers

This discussion has been closed.