Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove search filter on Datatable

Tags:

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

like image 436
CSharpNewBee Avatar asked Dec 10 '14 13:12

CSharpNewBee


People also ask

How do I remove search and show entries in dataTable?

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

How to search in DataTables?

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.

How dataTable search works?

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


1 Answers

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(); 
like image 90
Leandro Carracedo Avatar answered Oct 25 '22 03:10

Leandro Carracedo