Multi-table search
Multi-table search
I have two DataTables on the same page. Both are fully functional. One needs to have more columns that the other and I there are business reasons I cannot combine them in a single table. I want to be able to search both tables by typing in the DataTables search box for either table. How can I make this happen? Both tables have the same class.
I can think of two possibilities for a combined search:
- Add a function to monitor keyup events and copy the text from one search box to the other to trigger the default search behaviour.
- Create an external search field, hide the DataTables default search field, and write a function to trigger the API search on both tables simultaneously.
Which would work better? What if I add more tables to this page in the future (a distinct possibility)?
Answers
Never mind. I found a most elegant solution here:
https://datatables.net/forums/discussion/comment/101201/#Comment_101201