Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reset the filters in a datatable

I am unable to clear the filters using the fnFilter().

Here is my HTML code :

<table id="todays _table>

               <thead>
                 <tr id="todays_search_input_feilds">
                     <td class="input_filter">
                        <input type="text" id="type" class="form-control search_events">
                    </td>
                    <td class="input_filter">
                        <input type="text" id="vendor " class="form-control search_events">
                    </td>
                </tr>
            </thead>
    </table> 

And Here is my JQuery Code

$('#todays_table').dataTable().fnFilter('');
    oTable.fnClearTable();

I tried clearing using the following approach:

$('input[class="form-control search_events"]').val('');

But the problem with this is that, it is clearing the value but the data is not loading in the dataTable. It is loading only after i click on any of the filters

like image 886
Onera Avatar asked Oct 18 '16 14:10

Onera


1 Answers

To reset custom filters

If you're using custom filtering function as in this example, you need to clear controls involved before filtering and redrawing the table.

$('input.search_events').val('');
$('#todays_table').dataTable().fnDraw();

To reset global search

  • jQuery DataTables 1.9+

    Call fnFilter() API method with empty string as a first argument to reset the global search and redraw the table.

    For example:

    $('#example').dataTable().fnFilter('');
    
  • jQuery DataTables 1.10

    Call search() API method with empty string as a first argument followed by call to draw() API method to reset the global search and redraw the table.

    For example:

    $('#example').DataTable().search('').draw();
    
like image 63
Gyrocode.com Avatar answered Sep 19 '22 19:09

Gyrocode.com