vincjo / datatables

A toolkit for creating datatable components with Svelte
https://vincjo.fr/datatables
MIT License
372 stars 15 forks source link

How to access value of Th Filter #25

Closed JLLMNCHR closed 1 year ago

JLLMNCHR commented 1 year ago

In the following scenario, the filter is still applied, but the value is not displayed:

  1. Fill the Id filter with something, for example "ab". (The filter is applied correctly.)
  2. Click the New button to register a new element.
  3. I hit the Back button.
  4. It is observed that the filter is still applied, BUT the value "ab" has disappeared:

Some help will be appreciatted. Maybe some public method in Filters.ts to access the value of each filter or something like that...

Thanks in advance!

image image image

vincjo commented 1 year ago

Thanks for the illustration.

It seems that the value is correctly registred into the filters store. But when you go back, ThFilter component is remounted with the default filter value which is an empty string ''.

If you can keep your table component behind your create form - for example by using a modal, you won't have this problem anymore (I guess currently your table component is destroyed, replaced by a form and then remounted after form validation)

To my knowledge there is no simple way to bind the input value (DOM) to the applied filter

Alternatively, you can use the handler.clearFilters() method which removes all applied filters

vincjo commented 1 year ago

To illustrate, this way the filter value won't disapear : image