Clear .search() by clicking a button / editor (serverside)

Clear .search() by clicking a button / editor (serverside)

CapamaniaCapamania Posts: 233Questions: 81Answers: 5
edited April 2016 in Editor

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

Answers

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5

    Anybody an idea?

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Answer ✓

    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

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5

    I was thinking to complicated :-) It's working now, thanks a lot!

This discussion has been closed.