Clearing search box behavior

Clearing search box behavior

awarnockawarnock Posts: 13Questions: 3Answers: 0

I have a question about clearing the search box for a table. If I enter a string in the search box, it behaves like a filter - the rows which do not match the search text are hidden from view. If I just delete the search string, the hidden rows become visible immediately.

I'm trying to implement a "clear search" link to do that for me. I have set up the call using

$('#foo').DataTable().search("").draw()

and it works except... it refreshes the page with an Ajax call, rather than just unhiding the hidden rows.

This is problematic for me because I have a couple of pages where I'm using jQuery tabs to show multiple tabs on a single page, and have separate tables on the different tabs. The page refresh does not always bring me back to the previously active tab.

My question about DataTables is why does the search("") trigger a page refresh, rather than simply unhiding the filtered rows? And is there a way to get the hidden rows to display again without reloading the page?

Thanks.

Answers

  • kthorngrenkthorngren Posts: 21,329Questions: 26Answers: 4,949

    My question about DataTables is why does the search("") trigger a page refresh,

    Sounds like you have server side processing enabled which will send an ajax request to the server for any search, sort or page action to fetch the rows for the current page.

    If you aren't using server side processing then the ajax request is outside of normal Datatables behavior. In this case we will need to see the code you have or better a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • awarnockawarnock Posts: 13Questions: 3Answers: 0

    Thanks. I'll whip together a sample.

Sign In or Register to comment.