pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.79k stars 1.57k forks source link

Order indices in dynamic filter form #2310

Open LeXofLeviafan opened 1 year ago

LeXofLeviafan commented 1 year ago

As far I'm aware, the number in the fltN_ part of filter name refers to the filter order in the form, intended to retain said order on page refresh; and in the form itself it's handled by the lastCount variable.

The way it's currently handled, however, is as follows:

Is this actually the intended behaviour? Because I'm pretty sure the intuitively expected behaviour would be for the filters to retain their indices and UI order across page refreshes (except for when a filter is removed, anyway).

LeXofLeviafan commented 1 month ago

Case in point: in a table without sortable columns, I've implemented sorting as a custom ‘filter’. This had a side effect of allowing to sort by multiple fields (e.g. “sort records by title in reverse order, and sort those with the same title by URL instead”) ?flt0_order_by_title=desc&flt1_order_by_url=asc initial filters Now suppose the user wants to change the primary sorting field without changing the secondary one. He'll be expecting for the filters he set to retain their order after pressing ‘Apply’, right? updating filters And yet what he gets after submitting his changes will be… ?flt3_order_by_tags=desc&flt1_order_by_url=asc after applying

LeXofLeviafan commented 1 month ago

Example of filters being reordered when following pagination links:

Page 1 (initial) ![page1](https://github.com/user-attachments/assets/10a1ae5d-1c5b-4a79-b96b-23c527ce93eb)
Page 2 (opened from page 1) ![page2](https://github.com/user-attachments/assets/6c9039ad-7a05-477f-a6c3-2e6a45cd95dc)
Page 3 (opened from page 2) ![page3](https://github.com/user-attachments/assets/091cce34-f98e-46f2-8230-72a0cafd305b)
LeXofLeviafan commented 1 month ago

An external ad-hoc fix was implemented in this pull-request (see bukuserver/static/bukuserver/js/filters_fix.js for the frontend fixes, and bukuserver/views.py for the backend fixes).

Note that since it's an external fix, the pagination links are fixed in the JS (the part starting with .pagination a:not([href^=javascript]) selector search), instead of fixing their generation code.