Multiple DataTables with seperate Custom filter for each table on same page
Multiple DataTables with seperate Custom filter for each table on same page
najram94
Posts: 1Questions: 1Answers: 0
Hi,
I have 2 tables in same page, let say
$('#report-table1').DataTable();
$('#report-table2').DataTable();
No I want to add custom filter for each datatable using
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
}
);
but above filter works only for one table. How to add different filter function for each datatables in same page. Please help me. Thanks in advance
Answers
Here is an example of two tables based on the Range Search example::
http://live.datatables.net/tihuyiqi/1/edit
Kevin
Your simply doing a wrong approach here.
$.fn.dataTable.ext.search.push
has another purpose which you should never use when you multiple datatables in the page that you want to differently filter. The easiest way to build a custom search for a specific table is to build an array of unique ids for your data and later search it in your column id. Example:dreiquevada solution works well.
Thanks for sharing!
The only thing I had to change was the Reg Exp.
The one I've used is:
'^.*\\b(' + searchIds.join("|") + ')\\b.*$'
I came across this when i was searching for the solution on this issue,but um not sure if its a good use of
$.fn.dataTable.ext.search.push(
datatable function is there better way to code this. Can someone help?@TumeloM We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
You don't need that twice. Once will do.
$.fn.dataTable.ext.search.push will be executed for all data tables on the page.
In this (not so neatly coded) example I filter data from 5 different data tables. I don't need to know for what table $.fn.dataTable.ext.search is being executed. I just check whether the respective table rows are passed into the function:
- row.contract
- row.variable
- row.fixed and
- row.cashflow
- row.contract_has_infoma