Clear the datatable column filters using a button
Clear the datatable column filters using a button
Good Day,
I usually do things with PHP and when I have come into this jquery datatable plugin which is a good feature and I so love it. I had bump into some issues. I am fairly new to the javascript and jquery environment and still coping up with how it works.
My goal is to clear the column filters. Found one solution but all it does is clear the text in the search field but not the column filter.
Below is my code.
Button for clear column filter.
//datatable $(document).ready(function() { $('#datatable').DataTable( { dom: 'Bfrtip', buttons: [ { text: 'Refresh', action: function ( e, dt, node, config ) { var table = $('#datatable').DataTable(); table .search( '' ) .columns().search( '' ) .draw(); } } ,'excelHtml5','pdfHtml5','print'], "order": [[ 7, "asc" ]] } ); } );This is how i display my column filter
//column filter $(document).ready(function() { $('#datatable tfoot th').each( function () { var title = $(this).text(); $(this).html( '' ); } ); var table = $('#datatable').DataTable(); table.columns().every( function () { var that = this; $( 'input', this.footer() ).on( 'keyup change', function () { if ( that.search() !== this.value ) { that .search( this.value ) .draw(); } } ); } ); } );Any help is highly appreciated.
Answers
Make this the function for refresh and it should work.
$("#datatable").DataTable().search("").draw()
@glenderson
Thank you for taking time to reply to inquiry. I will give this a try
I'm looking to do something similar.
The above code clears the main search filter, but not the individual columns (at least not for me).
Here's my working code: