Data Table Filter History

Hi all,
I just want to refactor some old vue-datatables which are storing the filter history in local storage.
When the table gets visited again, the old filter settings were loaded from the history.

Now I want remove Vue from my project and use only the TALL stack.
I followed Calebs table screencast videos and added some advanced filters.

What would be the best way to store the filters like with my old vue-datatables?

Should I store them via javascript in the local storage like before and load the querystring inside of the livewire component? Or would you rather put them into a laravel session and load the filters from a long living session? Is there another way to think of?

Kind Regards
Chris

The term “best” is subjective, it depends on your use case and requirements.

Storing the filter settings/history in local storage is a nice option and will be more performant than storing this information in a session (less data along the wire, but arguably a micro optimisation). The data will also persist longer than however long you set your session lifetime which I think is nice from a users perspective.

Storing filter settings in a persistent data store could be an option if you are interested in what your users are filtering on or want to perform some analysis on their searches. You might want to be able to provide a “popular searches/filters” for example, again depends on your use case.

Probably not the definitive answer you wanted, but hopefully gives you something to consider and make a choice based on your needs.

Hi @Veleous , thanks for your answer. Really appreciate it. :slight_smile:

We have multiple different types of tables (invoices, customers, orders etc) with different filter options.
We are only 20 people to use the it in the admin background.
I think the easiest/quickest way would be to use the session driver right?

The option with the persistent data store sounds good, too.

But I’m still wondering if the local storage would be the way to go, if it should be used on a public website. Or would you rather use the persistent data store?

Unfortunately I couldn’t find any existing livewire packages (datatables) which are storing filters in the local storage.

A way to go would be to use alpinejs to push the local storage values to livewire right?

The session driver will likely be the simplest/quickest to implement yes but is obviously tied to your session lifetime so when that expires the data is lost. That may not be an issue for you though.

I would use the local storage option if I wanted the data to persist longer than the session lifetime and didn’t care about performing any analytics on searches/filtering.

Yeah, you will most likely need to use a combination of Livewire with Alpine to marshal your data between Livewire and local storage.

1 Like