Project

General

Profile

Actions

Feature #44406

open

Persist manually adjusted sort order in tables that belong to self-designed queries

Added by Maik Rohde 2 months ago. Updated 10 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Issues filter
Target version:
-
Resolution:

Description

Hello,

To explain my problem properly I have to write a small preface first:

Since a couple of months I am responsible for the Redmine-System of a small business. Having had an administrator that tended to be rather lazy, the version I was confronted with in January this year was actually Redmine 3.3.3. No joking.

I managed to move this entire system to version 7.0.0 properly now.


But, using this brand new version of Redmine, the staff now claims that "back then" with version 3.3.3 one could

A) open a self-designed query
B) sort the data with the sort options of the table headers
C) move on to another query
D) sort things there differently
E) and when coming back to the former query, the manually set up sort order via the table headers still was in place and worked.

Redmine somehow persisted this during the entire session for the view of every single query.

Now, with version 7.0.0, this is no longer the case. I can copy this.

When now

A) setting up a personal sort order different from the default sort order of the query (see Screenshot 2026-08-31 233938.png)
B) leaving the view of this particular query to another query's view (see Screenshot 2026-08-31 234017.png)
C) and then coming back to the former query, the sort order of the table is back to default (see Screenshot 2026-08-31 234101.png)

So here is my feature requirement, as my colleagues are pretty annoyed due to this lack of comfort:

Can you please make Redmine persist again personal sort order settings inside self-designed queries?
Each view should somehow memorize the set up of the table filters during the entire session.

Many thanks in adavance.


Files

Screenshot 2026-08-31 234017.png (91.2 KB) Screenshot 2026-08-31 234017.png switched to another query Maik Rohde, 2026-09-01 12:27
Screenshot 2026-08-31 234101.png (91.7 KB) Screenshot 2026-08-31 234101.png back to first query, sort order is gone Maik Rohde, 2026-09-01 12:27
Screenshot 2026-08-31 233938.png (93.4 KB) Screenshot 2026-08-31 233938.png set up sort order by "last changed" descending Maik Rohde, 2026-09-01 12:27
0001-Keep-the-sort-order-of-a-saved-query-in-the-session-.patch (4.1 KB) 0001-Keep-the-sort-order-of-a-saved-query-in-the-session-.patch Florian Walchshofer, 2026-10-20 21:30
0001b-Add-an-option-to-keep-the-current-sort-order-when-se.patch (7.62 KB) 0001b-Add-an-option-to-keep-the-current-sort-order-when-se.patch Florian Walchshofer, 2026-10-23 20:47
Actions #1

Updated by Florian Walchshofer 15 days ago

The behavior of 3.3 was a side effect of the old sort_helper: the sort order was stored once per page in the session and applied to every query. Since r16390 (3.4.0), the sort order belongs to the query.

It is therefore expected that selecting a saved query from the sidebar applies the query’s sort order. Users in our production environment have requested the same behavior.

When a saved query is sorted by clicking on a column header, the sort order is stored in the session (session[:issue_query][:sort]), but it is only read back for unsaved queries. With a saved query:

  • After going back to the issue list from an issue (e.g. with the "Issues" tab), the list is sorted by the default sort order of the query again.
  • The Previous/Next links and the "x of y" counter on the issue page use the default sort order of the query, not the order of the list the issue was opened from.

Steps to reproduce:

  1. Create a saved query sorted by # ascending.
  2. Select the query and sort the list by # descending by clicking on the column header.
  3. Open an issue: "Next" goes to the issue with the next higher ID instead of the next lower one.
  4. Click on the "Issues" tab: the list is sorted by # ascending again.

The attached patch (0001-Keep-the-sort-order-of-a-saved-query-in-the-session-.patch):

  • applies the sort order from the session to saved queries as well, in QueriesHelper#retrieve_query and #retrieve_query_from_session.
  • adds the sort order to the "x of y" link on the issue page for saved queries. Without it, the link opens the query with its default sort order, and the page number, which is calculated from the position in the sorted list, can point to the wrong page.

Selecting a query from the sidebar still resets the sort order to the default of the query. Functional tests are included.

Keeping a separate sort order for each saved query during the session, as requested here, would be a further step on top of this.

Maik, would it be possible for you to test the patch on your instance?

Expected behavior:

  1. Select a saved query and sort the list by clicking on a column header.
  2. Open an issue: Previous/Next and "x of y" follow the selected sort order.
  3. Click on "x of y" or on the "Issues" tab: the list keeps the selected sort order.
  4. Select the query in the sidebar again: the default sort order of the query is used, as before.

Please let me know whether this helps in your case, or whether you need the sort order to be kept when switching between queries.

Actions #2

Updated by Maik Rohde 14 days ago

Hwllo Florian,

I'll try to test it within the next 24h.

I'll keep you updated.

Actions #3

Updated by Maik Rohde 14 days ago

Hello Florian,

I am sorry to have to ask but this is the first time I tried to apply a patch. And something went wrong. I tried both ways described in your manual but both fail. Here is the terminal output:

-- Here I reckon that this patch is not supposed to be applied with "patch", as its content looks more like git.

redmine@aserver:/redmine/redmine-7.0.0$ patch p0 < 0001-Keep-the-sort-order-of-a-saved-query-in-the-session.patch
can't find file to patch at input line 5
Perhaps you used the wrong p or --strip option?
The text leading up to this was:
-------------------------
|diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb |index 144542a73..d7b2694bd 100644 |--- a/app/controllers/issues_controller.rb |+++ b/app/controllers/issues_controller.rb
--------------------------
File to patch:

-- But then I am not sure why the GIT-way fails as well.

redmine@aserver:/redmine/redmine-7.0.0$ git apply 0001-Keep-the-sort-order-of-a-saved-query-in-the-session-.patch
error: patch failed: app/controllers/issues_controller.rb:552
error: app/controllers/issues_controller.rb: patch does not apply
error: patch failed: app/helpers/queries_helper.rb:386
error: app/helpers/queries_helper.rb: patch does not apply
error: patch failed: test/functional/issues_controller_test.rb:2725
error: test/functional/issues_controller_test.rb: patch does not apply
redmine@aserver:/redmine/redmine-7.0.0$

Do you have any hint for me?

Actions #4

Updated by Florian Walchshofer 14 days ago

Hi Maik,

no problem. Use -p1 instead of -p0 (run it in /redmine/redmine-7.0.0):

patch -p1 --dry-run < 0001-Keep-the-sort-order-of-a-saved-query-in-the-session-.patch
patch -p1 < 0001-Keep-the-sort-order-of-a-saved-query-in-the-session-.patch

If the first command reports no "FAILED", run the second one and restart Redmine. To undo it: patch -p1 -R < 0001-Keep-the-sort-order-of-a-saved-query-in-the-session-.patch

(git apply most likely failed because the file got Windows line endings when it was copied to the server; patch handles that.)

Actions #5

Updated by Maik Rohde 13 days ago

This is the result of the dry run. Can I fix this in nano, maybe?

checking file app/controllers/issues_controller.rb
Hunk #1 FAILED at 552 (different line endings).
1 out of 1 hunk FAILED
checking file app/helpers/queries_helper.rb
Hunk #1 FAILED at 386 (different line endings).
Hunk #2 FAILED at 416 (different line endings).
2 out of 2 hunks FAILED
checking file test/functional/issues_controller_test.rb
Hunk #1 FAILED at 2725 (different line endings).
1 out of 1 hunk FAILED

Actions #6

Updated by Florian Walchshofer 13 days ago

Hi Maik, I answered in the forum to keep this issue short: Applying the patch from #44406 fails with CRLF line endings

Actions #7

Updated by Florian Walchshofer 12 days ago

I moved the previous patch (0001) to Defect #44667: Sort order of a saved query is lost when going back to the issue list, and ignored by the previous/next links,
because it fixes a separate defect.

As discussed in the forum RE: Applying the patch from #44406 fails with CRLF line e..., a colleague of Maik needs the sort order to be kept when switching between queries, because an issue passes through up to 10 queries. The attached patch (0001b-Add-an-option-to-keep-the-current-sort-order-when-se.patch)
adds an option to saved queries: "Keep the current sort order when selecting this query".

  • The option is off by default, so existing queries keep their behavior: selecting a query from the sidebar applies its sort order.
  • When the option is set, selecting the query keeps the sort order of the list that was displayed before, either a manually selected one or the sort order of the previous query.
  • The option is stored in the options of the query, like the Gantt options, so no migration is needed.
  • Functional tests are included.

The patch applies to trunk and to 7.0-stable, with or without the patch from #44667. Both patches can be applied in any order. For a consistent behavior after switching (e.g. going back to the list from an issue, previous/next links), the fix from #44667 is needed as well.

Actions #8

Updated by Maik Rohde 12 days ago

Hello Florian,

First of all, I can confirm that the first patch does what it is supposed to do. The manually set table sort order of the current query is being kept no matter what tab I click in between. Many thanks for that.

And even more appreciation for the delivery of the second patch at lightspeed. I'll right now implement it and check the system's behavior. I'll update this ticket afterwards.

Actions #9

Updated by Maik Rohde 12 days ago

Hello Florian,

Here is my result:

I could patch the system without any problem. The server restarted properly afterward. As well I could find the newly implemented checkbox inside each query.

But unfortunately, there is a problem I came across. I ran the tests in my test environment which is actually the same Redmine Version as on the productive server. So this problem would also occur on the main server.

I tested with "personal" queries and "global" queries and I also tested as Administrator and as a normal User. Both did not make any difference, wich is good.

But I faced two issues. The first glitch is, that the sort order gets lost when there is at least one query that does not apply the new feature (checkbox unchecked). As expected it then uses its default sort order, but when I get back to a query that is supposed to memorize the previous manually set sort order, this order is lost. Even this query sorts by its default again.

When I check the checkbox in all queries, the memorization works.

Which leads to glitch number two. The last sort order is being applied for all queries. So let's say I set a manual sort order in query1 and switch to query3, then the previous sort order of query1 is being applied for query3 as well. Changing the sort order of query3 and jumping back to query1 applies query3's sort order to query1. There seems not to be one memory for each but only one memory for all queries.

I'am terribly sorry to have to report this, because I really appreciate the effort you put into this requirement, but as long as the sort order is kind of being interited when switch among queries, it still does not fit my colleagues needs.

Actions #10

Updated by Florian Walchshofer 11 days ago

Thanks for testing, Maik. Before I rework the patch, I would like to agree on the behavior. There are two possible variants:

Variant 1: the own sort order is carried over to the next query with the new option

  • When the list is sorted by clicking on a column header, this sort order is carried over when switching to a query with the option.
  • When switching to a query without the option, its sort order is applied and the own sort order is forgotten, also for the following queries.
  • The first problem from note-9 remains by design: after switching through a query without the option, the following queries with the option use their own sort order again.
  • The second problem from note-9 remains as well: there is no sort order per query. Switching from query 3 to query 1 carries the sort order of query 3 over to query 1.

Variant 2: each query remembers its own sort order

  • When a query is sorted by clicking on a column header, this sort order is remembered for this query in the session.
  • When the query is selected again later, its remembered sort order is used. Queries that were never sorted manually use their own sort order.
  • This fixes both problems from note-9. It is what was originally requested in this issue ("each view remembers its table setup for the session").
  • This could work with or without the option on the query.
  • It needs more space in the session, which is stored in a cookie limited to about 4 KB. The number of remembered queries would have to be limited.

Example with query 1 (sorted by priority), query 2 without the option (sorted by due date) and query 3 (sorted by status), all other queries with the option:

Step Variant 1 Variant 2
Select query 1, sort it by "Updated" Updated Updated
Select query 2 (without the option) Due date Due date
Select query 3 Status Status
Sort query 3 by "Subject" Subject Subject
Select query 1 again Subject Updated

In both variants, nothing is stored permanently: the remembered sort orders are only kept in the session of the user. Other users, including users of the same public or global queries, are not affected and still get the sort order of the query.

I would prefer variant 1: it needs no additional data in the session, only a check when switching queries, and the behavior stays simple.
Which variant fits the needs of your colleague better?

Actions #11

Updated by Maik Rohde 11 days ago

Hi Florian,

Although I see your point in keeping it simple, the answer is, that option 2 is definitely the wanted behavior.

Each query's view is expected to keep its own manually adjusted sort order inside the current session. Independantly for each user.

So I'd actually agree that the option-checkbox won't be needed in my particular case, as they will ask me to activate it on all queries anyway. You can remove it, if you prefer it.


Just to explain why this is necessary:

The entire company has, back then, defined round about 10 workflow steps (represented by queries that filter for the matching values) for passing an issue through the workflow. From the initial request by a new client until the generation of an invoice. They all have to use the same set of global queries which have only one predifined sort order each. No one uaes local/personal queries.

But each of them has individual habits concerning data represenation. And thus, the default sort order does not fit the need of each staff member. So they adjusted the sort orders of each query individually inside their sessions. Which perfectly persisted all day long even when they switched among them, and it worked for years. Until I came along and replaced release 3.3.3 by 7.0.0 for severe security reasons an the need to keep up with the latest security features as 2FA and stuff. This now secures the data by state of the art mechanisms but destroyed their accustomed way of working. And this is why they ask me frequently to do something about it.


Many thanks in advance, that you support me in this case.

Actions #12

Updated by Florian Walchshofer 10 days ago

Hi Maik,

Since a per-query sort order in the session is unlikely to make it into Redmine core, I implemented variant 2 as a plugin:

Redmine query sort memory

About the "lightspeed": I have to confess I had some help from Claude. Turns out the speed of light is still the limit, but only because the AI has to wait for me to read its code. ;-)
Honestly, tools like this are going to turn the way we write software upside down.

Please let's continue the discussion, bug reports and feature requests on GitHub:
flowalchs/redmine_query_sort_memory

The core defect fix for saved queries is still tracked in #44667.

Actions #13

Updated by Maik Rohde 10 days ago

Hi Florian,

just to make it visible to all Users, that might stumble somewhen into this issue:

Your solution perfectly works. From my point of view this ticket is solved. And it is absolutely understandable and okay for me, putting this into a plugin.

Many thanks for that!

Actions #14

Updated by Maik Rohde 10 days ago

PS: Sorry, but I could not find any option to put a comment in GitHub although I have an account and am logged in.

Just one small remark. In the README-section in Github you mention, that there is nothing else necessary but putting the plugin into the plugins-folder and restart Redmine. This is almost true.

I'd suggest to recommend in your README at least to run "bundle install" once, because I was lacking the "simplecov-cobertura" gem which your plugin needs. I was wondering why the Redmine-server did not start again. Thanks to the test you provided I found it out.

After running bundle install everything was fine.

Actions

Also available in: Atom PDF