Remove search filter on Datatable

CSharpNewBee picture CSharpNewBee · Dec 10, 2014 · Viewed 43.9k times · Source

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).

Answer

Leandro Carracedo picture Leandro Carracedo · Dec 10, 2014

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();