From 31e3049bddcc6feb762cb1c807215f298e88166e Mon Sep 17 00:00:00 2001 From: Wieland Schopohl Date: Thu, 16 Apr 2026 11:30:44 +0200 Subject: [PATCH] Fix sort order after column reorder on page reload 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 9ac234831..98b9cf29d 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] } });