How to do a live search results using DataTables
How to do a live search results using DataTables
wfa
Posts: 3Questions: 1Answers: 0
I'm using DataTable with Ajax that gets JSON from Java Servlet. How can I do a live search where data is actively fetched as the user type in the search box. Is there a specific DataTables method to do that?
Here is my current page (it's in Arabic)
https://makhtutat.com/manuscripts.html
Answers
Looks like you've created your own
input
element. That's absolutely fine, you just need to add an event listener to it (keyup
andinput
would do), and then call thesearch()
method with the input value.Allan
Thanks for the reply
But doesn't this search works on the resulting table locally?
It will not fetch new data as I type in the main #searchbar input box.
Do you have an existing web page where this idea is implemented?
This is what Allan meant - please see example here.
As you've added your own
input
for the filtering, you need to add code/events to search when strings are entered:Colin
Do you mean you need to Ajax fetch new data on each key press? If so, make your Ajax call to get the new data based on to the search value and use
clear()
and thenrows.add()
to clear and then add the new data to the table.Allan