1

I have a Datatable that loads with new data every time the user changes the option from a dropdown list for which I want to keep the same filter even even if the table content changes. I've tried to get the current value from the search input by using:

$('div.dataTables_filter input').val() 

suggested in https://datatables.net/forums/discussion/242/getting-filter-text

or

table = $("#datatable-buttons").DataTable({...});
table.fnSettings().oPreviousSearch;

but without any success :( Is there a way to get the filter input text?

1 Answer 1

5

Simply use search() without params, then it return the current filter

var filter = table.search()

or you kan keep on track of the current search by using the search.dt event :

table.on('search.dt', function() {
  var input = $('.dataTables_filter input')[0];
  console.log(input.value)
})

demo -> http://jsfiddle.net/44datL5b/

Sign up to request clarification or add additional context in comments.

1 Comment

Wow! Thanks a lot! I didn't had any idea that the only thing to do was just to type .search() :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.