How To Clear Custom Filters AND Global Search

How To Clear Custom Filters AND Global Search

MagicSquaresMagicSquares Posts: 22Questions: 7Answers: 0

I'm trying to include a button on my page that will clear both the custom filters I've built AND the global search box supplied by DataTables, and then re-draw the table.

This is the code I currently have that is triggered by clicking the pseudo-button (i.e. styled text):

$(document).ready(function() {
  $('#clearf').click(function(){
    $('.bs-filters').val('');
    $('input[type=search]').val('');
    var table = $('#bs-results').DataTable({
    retrieve: true
});
    table.draw();
  });
} );

This will clear the custom filters, and re-draw the table, but it doesn't clear the global search box.

If I remove the table.draw() statement, it will clear the custom filters AND the global search box, but it won't re-draw the table.

How can I get my button to do both?

Here's the debug, if it helps:

https://debug.datatables.net/onadod

Thanks!

Mark

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    I would suggest using search() to clear the existing search term in DataTables - just pass in an empty string.

    Allan

This discussion has been closed.