add a button to clear search field

add a button to clear search field

bjh27bjh27 Posts: 3Questions: 2Answers: 0

Is there a way to add a button next to the search filed that would clear the search field when clicked?

This question has an accepted answers - jump to answer

Answers

  • bhaulikbhaulik Posts: 10Questions: 3Answers: 0

    You can use the buttons API to listen for a click event and use jQuery in coordination to select the input in the search field and set it to an empty string when clicked

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin
    Answer ✓

    The documentation for creating a custom button is available here. In this case you could use search() to clear the main search for the table - e.g.:

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

    Allan

  • bjh27bjh27 Posts: 3Questions: 2Answers: 0

    Thanks!

This discussion has been closed.