morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
204 stars 64 forks source link

Fix column filter when savedstate is activated #74

Open etiennepouliot opened 2 years ago

etiennepouliot commented 2 years ago

If we enable state saving (https://datatables.net/examples/basic_init/state_save.html), on a refresh, the column will be filtered but it will not be visible.

IE, without this patch : image

with this patch : image

etiennepouliot commented 2 years ago

Failed flake8 are fixed in #73

olevchyk commented 1 year ago

I'm also interested in this use-case, is there any alternative way of doing this? like per-populating initialSearchValue for the column filters based on some URI param that holds the state on the backend? Any suggestion or comments regarding the work done in this pr ?

drowe-official commented 12 months ago

Would also like to see this. A quick glance at the proposed changes- it seems to be the right thing to do. There's a few threads on datatables.net about how to do something like this, and it looks in line with the proposed changes.

See https://datatables.net/forums/discussion/56943/persist-search-value-of-individual-column-with-statesave

tl;dr: Grab the data.columns[i].search.search value and set your custom filter to this value. Rinse and repeat for all custom filters/saved search values.

Note- The linked page's solution uses stateLoadParams and other state callbacks to set the filters. This doesn't seem to work with django-ajax-datatables as the custom filter inputs only exist after these callbacks. I couldn't get them to work, in any case