One way would be to change the input type of the filter to "search" - then HTML5 browsers will automatically show a clear widget. However, you'd have to press return after clicking it, so I wanted a one-click solution.
Here's what I came up with. It works with DataTables 1.9.
// Setup DataTable Defaults
$.extend( $.fn.dataTable.defaults, {
fnInitComplete: function(oSettings, json) {
// Add "Clear Filter" button to Filter
var btnClear = $('<button class="btnClearDataTableFilter">CLEAR</button>');
btnClear.appendTo($('#' + oSettings.sTableId).parents('.dataTables_wrapper').find('.dataTables_filter'));
$('#' + oSettings.sTableId + '_wrapper .btnClearDataTableFilter').click(function () {
$('#' + oSettings.sTableId).dataTable().fnFilter('');
});
}
});
is it possible explain how do that for column filter
ReplyDeletethank you for sharing solutions
i found a solution for reset column filter with your code
ReplyDeletereplace fnFilter(''); with fnFilterClear();
one line extra
$('#example thead input').val('');
example because i change table to exaple
thead because i prefer a tfoot
thank you i hope this help (sorry my english)
i forget to say and this
ReplyDeletehttps://cdn.datatables.net/plug-ins/1.10.9/api/fnFilterClear.js">