I have applied a button in my DataTable, which on click, filters the data table, to just show the clicked row.
table initialization is:
var oDatatable = $("#tblDataTable").DataTable({ dom: '<"top"CRTl><"clear">rt<"bottom"ip><"clear">', columns: [ { data: 'Message' }, { data: 'MessageId' }, { data: null, "defaultContent": "<button id=\"tblRowData\">Click</button>"} ], "columnDefs": [ { "visible": false, "targets": 0 } ] });
and my click event is:
$('#tblDataTable tbody').on('click', 'button', function (event) { var data = oDataTable.row($(this).parents('tr')).data(); oDataTable .columns(8) .search(data['MessageId']) .draw();
This all work perfectly fine, but now I want to reset the filters, when any other action on the page is carried out. For instance, changing a datetime picker.
How can I check if the datatable has a seach filter applied, and remove it (i.e. resetting the table back, prior to the click event).
To disable the "Show Entries" label, use "bInfo", example: "bFilter" is the search component, but are active by default. $(document). ready( function () { $('#example'). dataTable( { "bInfo": false } ); } );
Searching on individual columns can be performed using the columns().search() and column().search() methods. DataTables has a built in search algorithm referred to as "smart" searching and is designed to make searching the table data, easy to use for the end user.
Searching in DataTables is "smart" in that it allows the end user to input multiple words (space separated) and will match a row containing those words, even if not in the order that was specified (this allow matching across multiple columns).
Maybe you are looking at something like this: http://www.datatables.net/plug-ins/api/fnFilterClear
You could clear the search in a very simple way:
var table = $('#example').DataTable(); table .search( '' ) .columns().search( '' ) .draw();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With