How to clear the search input from outside of DataTables
How to clear the search input from outside of DataTables
I have a DataTable that lives inside of a jquery dialog box.
When users click on a link in the table, I have jquery that loads an image and closes the dialog box.
If the users re-open the dialog without reloading the page, whatever search performed the last time the dialog was open and the table was visible is still applied.
Is there a way to clear the search box (both emptying the search input and re-displaying any hidden rows in the table) via a jquery command?
This question has an accepted answers - jump to answer
Answers
I tried to post a code sample, but I couldn't make it look readable. What the heck?
Details on code formatting are shown below the buttons for the input - see this page for examples.
Assuming you are applying a search using the API then it can also be cleared using the API (
search()
with an empty string). However, without a link to a test case I can't say much more than that.Allan
Go here: http://www.star.nesdis.noaa.gov/icvs-beta/status_NPP_sc_test.php
Click the button in the upper right labeled "Metrics Finder"
The table that pops up in the dialog is a DataTable instance. When users click on a link in the table, an image loads, the dialog box is closed, and I want to clear search at that point.
Did you try calling the
search()
method and thendraw()
(i.e.table.search('').draw();
? You need to calldraw()
to update the table as the documentation explains.Allan
The relevant script bit is:
Can these methods you reference be called from inside this script? That's what I need to be able to do.
Sure - the API manual describes how to access the API.
I guess another option would be to trigger the change event on the input element:
I would suggest you use the API as I suggested above, but that would also work.
Allan
that does work. The part I can't get to work is applying the "" value to the search.
ok, finally understand, it works.
I have a request: when I search your site / documentation for information, there is no way to say "only show me content from version 1.10 or later". I get results from older versions of the product constantly, which I know don't apply, but there is no good way to filter my results to only get answers that are relevant to the latest version of DataTables. If there was a way to do that, I would have been much better able to figure this out myself.
If the page looks ugly then it is old - and should have a nice big notice at the top stating that. In the forum legacy information should also have a notice.
The reference contains 1.10+ information.
An improved site search is something I know needs to be added. The current Google custom search really isn't great.
Allan
Allan -- thanks. My datatables implementation is now working gangbusters, thank you so much for this very useful suite of tools.
If you go here:
http://www.star.nesdis.noaa.gov/icvs-beta/status_NPP_CrIS.php
and click the 'Finder' button in the upper right, it pops up a dialog with a generated datatable that lets users search the page for desired satellite metrics. click the link, and the desired metric is displayed, the dialog box closes.
I know which pages are and are not 1.10 information, I just wish I could limit my search to them, to make it faster to find things.
That's a really nice use of DataTables - thanks for showing me!
I've got a book on Sphinx on my desk waiting for me to get to grips with the site's search. Hopefully, since the data is structured it should perform quite well (once done...).
Allan