Clear .search() by clicking a button / editor (serverside)
Clear .search() by clicking a button / editor (serverside)
I want to deselect a filter by clicking a button. With the following I .search() and .draw() specific columns in a editor (serverside) table:
$('.search-input').on( 'keyup click', function () {
var a =$(this).attr('data-column');
var b =$(this).val();
table.columns(a).search(b).draw();
});
The following then clears the input text and reloads the table, but the previous search result remain.
$('.clearFilter').on('click', function() {
$('.search-input').val('');
table.ajax.reload();
});
'After clicking' in the input text field, the table then goes back to default. How can I have the table to go back to default by clicking the .clearFilter button right away?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Anybody an idea?
You need to use
columns().search()
again to clear the values that DataTables is filtering on - it doesn't automatically get the value from the input box since it knows nothing about your external input element.Or use
$('.search-input').trigger( 'click' )
to execute your event handler.Allan
I was thinking to complicated :-) It's working now, thanks a lot!