Refresh DataTable data after clearing Search input field

Refresh DataTable data after clearing Search input field

fmsthirdfmsthird Posts: 8Questions: 2Answers: 0
edited August 2019 in Free community support

I'm trying to clear the Search input field when a button is clicked via jQuery.

    $('#clear-filter').click(function() {
      $('#filter-input').val('');
    });

The input was cleared but the Table is not refreshed or reset.

I actually had to hit backspace again before the data will show.
Is there any way I can reset the table after clearing Search input field without hitting backspace again?
Or are there any other way I can refresh the table.

Thanks

Note: Data is loaded from Server-side

Replies

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    edited August 2019

    You can use a blank search string with search(), for example table.search( "" ).draw();. The input will also be cleared with this statement.

    Kevin

  • fmsthirdfmsthird Posts: 8Questions: 2Answers: 0

    Hi Kevin,
    Thanks. I tried to apply it now. but it doesn't work.

  • fmsthirdfmsthird Posts: 8Questions: 2Answers: 0

    Tried like this

    $('#clear-filter').click(function() {
      $('#dataTable').DataTable().search( this.value ).draw();
    });
    
  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    Like I said you need to use a blank search string: search( "" ).

    Kevin

  • fmsthirdfmsthird Posts: 8Questions: 2Answers: 0

    Damn! Awesome it works like a charm.
    I thought I was posting a question and I was trying to find where to accept your answer @kthorngren

This discussion has been closed.