Is it possible to clear the basic keyword search field when the SearchPane clear button is clicked?

Is it possible to clear the basic keyword search field when the SearchPane clear button is clicked?

rkosekrkosek Posts: 2Questions: 1Answers: 0
edited May 2023 in Free community support

Hi,

I've been integrating with DataTables for a client, and we all love it. However, they've asked if the Clear button from the SearchPane extension can be made to clear the default Search by Keyword input.

I can't find a way to add second event to the button via the API.

So the route I think I need to take is to add a custom "Clear" button, which clears all search panes and empties the active search.

How would I code the button action to reset the Keyword and SearchPane selections both?

Handler

So far this is what I tried, and it didn't truly reset the search.

buttons: [
    {
        text: 'Clear',
        action: function (e, dt, node, config) {
            dt.search('');
        }
    }
],

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,475Questions: 26Answers: 4,804
    Answer ✓

    So far this is what I tried, and it didn't truly reset the search.

    You need to add draw(), for example:

            action: function (e, dt, node, config) {
                dt.search('').draw();
            }
    

    You can right click and inspect the SearchPanes Clear All button to find the selector to use, something like this example:
    https://live.datatables.net/ximesucu/1/edit

    Kevin

  • rkosekrkosek Posts: 2Questions: 1Answers: 0

    Thank you Kevin, that works perfectly for this use-case. :)

Sign In or Register to comment.