Skip to content

Commit 31e3049

Browse files
committed
Fix sort order after column reorder on page reload
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.
1 parent a82d515 commit 31e3049

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

assets/controllers/elements/datatables/datatables_controller.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,16 @@ export default class extends Controller {
113113
return null;
114114
}
115115

116+
//The saved order index is visual (post-reorder). If colReorder state
117+
//exists, map it back to the original column index so the server sorts
118+
//the correct column. colReorder[visualIndex] == originalIndex.
119+
let columnIndex = order[0];
120+
if (saved_state.colReorder) {
121+
columnIndex = saved_state.colReorder[columnIndex];
122+
}
123+
116124
return {
117-
column: order[0],
125+
column: columnIndex,
118126
dir: order[1]
119127
}
120128
});

0 commit comments

Comments
 (0)