0

We can add search to a table defined using TabularTables and make it caseSensitive, smart and enterOnly. However, I don't see an option to clear the search field on table/page reload. Any idea how I can clear search?

In the table 'stateSave' is set to true and can't be turned off because I would like page size and sorting to be saved across page reloads.

https://github.com/aldeed/meteor-tabular#customizing-search-behavior

Srini K
  • 3,315
  • 10
  • 37
  • 47
  • 1
    Could you clear it in the enclosing template's `onRendered` handler? Presumably the search field has an identifier. – Michel Floyd Dec 07 '17 at 01:35
  • That didn't work. Even if the input element is cleared, the value gets restored from state of the datatable that is saved internally when datatable gets loaded. Had to clear the value of search in state to achieve this, but not sure how yet. – Srini K Dec 07 '17 at 16:02

1 Answers1

0

Update onRendered or onDestroyed template handler to clear the search value from datatable's state and redraw.

https://datatables.net/reference/api/search()

Template.your_template_name.onDestroyed(function() {
  var table = $('#your_datatable_id').DataTable({
    'retrieve': true
  });
  if (table.search() !== "") {
    return table.search("").draw();
  }
});
Srini K
  • 3,315
  • 10
  • 37
  • 47