jquerydatatables

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


Solution

  • 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