Custom filtering in multiple tables
Custom filtering in multiple tables
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
after reading
http://stackoverflow.com/questions/39119015/how-to-change-yajra-datatable-search-filtering-system/39120465#39120465
https://datatables.net/forums/discussion/19334/problem-with-multiple-datatables-on-same-page
my final solution:
var ptable = $('#table2').DataTable();
var rtable = $('#table1').DataTable();
var term;
$('#table1_filter input[type="search"]').keyup(function(e){
console.log("table1_filter");
var term = $(this).val();
});
$('#table2_filter input[type="search"]').keyup(function(e){
});