Searching Across Multiple Tables
Searching Across Multiple Tables
Hello.
I have multiple DataTables on the same page. I have one search box and I need to be able to search across all the tables simultaneously.
This page (https://www.datatables.net/examples/basic_init/multiple_tables.html) indicates, "Additionally, the API can be used to manipulate both together, or independently", bu no examples are given.
Here is how I create my DTs. There are several HTML tables that have the 'table-data' class.
var tables = $('.table-data').DataTable({
"bPaginate": false,
"columnDefs": [
{ 'orderable': false, 'targets': [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] },
{
"targets": 2,
"render": function (data, type, row) {
uniqueShareClasses[data] = data;
return data;
}
},
],
"info": false,
"order": [[0, "asc"], [1, "asc"]]
});
In my search function I have this code. My input box has an id of 'search'.
tables.search($('#search').val()).draw();
I seem to be able to search in the first table only. Non of the remaining tables are searched. Are there any examples of this?
Answers
I'm working on the same thing. I got search to work accross all tables, but I can't figure out how to disabled per table search so that only my universal search box works.
Here is what I used for universal search:
Now, if anyone can help me disabled the also included individual table search fields, that would be great.
Use:
to search all DataTables. Or:
The key is to make sure that your API instance selects multiple DataTables.
Allan
Use the
dom
option and remove thef
option.Allan