Programmatically clearing the current search?
Programmatically clearing the current search?
I have a web page with a simple Data Tables grid. This includes a standard search box. As the user types their search term, the grid gets updated accordingly. This is exactly what I would expect, and it's working fine.
However, to clear the search - and return the grid to showing the entire data set - it appears that the user has to return focus to the search box and then backspace over the entered text to delete it. This can be laborious, and perhaps not always intuitive.
Is there any way to programmatically clear the search box? Put another way, is there some way I can give the user a simple one-click method of clearing the current search?
Thanks in advance for any advice.
Mike
Answers
This example displays an
X
in the search input that can be used to clear the search:Does that not appear for you?
If you are creating a search input make sure it is of type
search
for theX
. If its a text input theX
won't be displayed. Or you can create a button to clear the search and use thesearch()
API` and pass in an empty string to clear the search.If you still need help please post a link to your page or test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
The clear X is very platform dependent. I never see it on Linux for example.
search()
is the way to clear the global search box programmatically, as Kevin says.Allan
Thanks, Kevin and Allan, for your replies. I'm not familiar with the search() API, so I'll study the documentation and then get back to you if I get stuck.
Mike