How To Reset Search That Contains Date Filter Range?
How To Reset Search That Contains Date Filter Range?
I have a datatable with 3 search filters with 2 buttons which is RESET and FILTER :-
1. Status
2. Facility Name
3. Date Filter : 2 date fields which FROM_DATE and TO_DATE
The search function works fine with any combination of the filters. However, if I used the date range, clicking on the RESET does not reset the datatable and redraw with the full original results but only shows the result of the last search using the date range filter. These is my RESET function:
$('#kt_reset').on('click', function(e) {
e.preventDefault();
$('.kt-input').each(function() {
$(this).val('');
table.column($(this).data('col-index')).search('', false, false);
});
table.table().search("").draw();
});
If I were to search without using the date filter, the RESET button works as normal. What am I doing wrong? Thanks.
Answers
To reset the column search use
table.column(0).search("").draw()
to reset column 0. Usetable.columns().search("").draw();
to reset the search for all columns. You will manually need to reset your inputs to the values you want.Kevin
Tried this but same thing... Works with other search filters but if I defined the date filter, RESET will not work and still show the filtered result.
This is my function for the date filter.
Could this be the cause of this issue? For me, it looks like that the data used by the date filter is not being cleared as the datatable still shows the same exact records. Any new idea how to fix this?
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin