fn.dataTable.ext.search.push for only one datatable?
fn.dataTable.ext.search.push for only one datatable?
tekuila
Posts: 24Questions: 5Answers: 0
Hi.
I use the code "initComplete: function () { .fn.dataTable.ext.search.push etc etc..." (full code below) and it messes up my other datatables.
I already put it inside of var table = $('#datatable').DataTable( {} ) and given the different datatables unique IDs.
How to implement this code for only ONE datatable?
Datatable: http://live.datatables.net/furexita/1/edit (datatables is not being loaded and I don't know why)
initComplete: function () {
$.fn.dataTable.ext.search.push(
function( settings, searchData, index, rowData, counter ) {
// Don't display rows if nothing is checked
if (filtered.length === 0) {
return false;
}
if (filtered.includes(searchData[10])) {
return true;
}
return false;
}
);
}
Thank you
- Jonas
This discussion has been closed.
Replies
Better to see this datatable (more simple): http://live.datatables.net/yihoxiyi/1/edit
Hi @tekuila ,
This thread should help, it's asking the same thing.
Cheers,
Colin
Thanks! I'm inserting the line "if ( settings.nTable.id === 'datatable' ) {" but it makes no difference - one of the other tables are still displaying "No results".
If I delete the below code then it displays results on the other table.
I'm initializing each datatable like this, but with different IDs.
Hi @tekuila ,
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
Thanks, heres a test case: http://live.datatables.net/jatesoda/1/edit
You can see the line "if (filtered.includes(searchData[6])) {"is removing the results one the second table because there is not a 6th column in the second datatable.
So the question is, how to make the checkbox code work for ONLY the first table so it doesn't interfere with the second? Thanks.
If I change that line to this:
if (filtered.includes(settings.searchData[10])) {
Then all data is loading correctly. But locally the other datatable is stuck on "Processing". Even though the data is not loaded from Ajax.
Getting "TypeError: settings.searchData is undefined"
I think I fixed it!
By adding the code below:
if ( settings.nTable.id !== 'datatable' ) {
return true;
}
Example here: http://live.datatables.net/jatesoda/2/edit
Thanks.
Hi @tekuila ,
There were a few problems with the code - table the wrong size, inconsistent variable naming, etc - but all fixed here. It seems to be doing what you want.
Hope that helps,
Cheers,
Colin
Hey guys!
Thanks for great examples!
In this examples, checkboxes filters exact phrase in the cell. Can filter a part of text in the cells? For example I want to filter "Architect" with checkbox and to return System Architect, Interior Architect etc...?
Thanks for your time!
@pristis Of course You can use any Javascript comparison method you need. You will want to make it as concise as possible to reduce delays. I took the last example, commented out the comparison and created one the loops all the search terms.
http://live.datatables.net/yeropoku/46/edit
Update one of the rows to have
Interior Architect
. Unchecking all butArchitect
should show both System and Interior Architect. One it finds a match it usesreturn true;
to display the row.Kevin