From 673d5b5e83108e94d16433c5b081af19337f8fa9 Mon Sep 17 00:00:00 2001 From: Wieland Schopohl <55855374+wschopohl@users.noreply.github.com> Date: Mon, 4 May 2026 06:16:02 +0900 Subject: [PATCH] Fix sort order after column reorder on page reload (#1346) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When columns are reordered via colReorder and the page is reloaded, the saved sort state uses visual column indices. These were sent directly as initial_order to the server, which interprets them as original indices — causing the wrong column to be sorted. Use the saved colReorder mapping to translate visual indices back to original indices before sending initial_order in the _init request. --- .../elements/datatables/datatables_controller.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/assets/controllers/elements/datatables/datatables_controller.js b/assets/controllers/elements/datatables/datatables_controller.js index 9ac23483..98b9cf29 100644 --- a/assets/controllers/elements/datatables/datatables_controller.js +++ b/assets/controllers/elements/datatables/datatables_controller.js @@ -113,8 +113,16 @@ export default class extends Controller { return null; } + //The saved order index is visual (post-reorder). If colReorder state + //exists, map it back to the original column index so the server sorts + //the correct column. colReorder[visualIndex] == originalIndex. + let columnIndex = order[0]; + if (saved_state.colReorder) { + columnIndex = saved_state.colReorder[columnIndex]; + } + return { - column: order[0], + column: columnIndex, dir: order[1] } });