From b6dd5bb881d574c81c57166764624789afeb3586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 8 Jul 2023 20:16:52 +0200 Subject: [PATCH] Fixed ordering columns of tables when columns were reordered --- .../elements/datatables/datatables_controller.js | 2 -- assets/js/lib/datatables.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/assets/controllers/elements/datatables/datatables_controller.js b/assets/controllers/elements/datatables/datatables_controller.js index 9587d7d1..df0dbbfc 100644 --- a/assets/controllers/elements/datatables/datatables_controller.js +++ b/assets/controllers/elements/datatables/datatables_controller.js @@ -68,8 +68,6 @@ export default class extends Controller { stateLoadCallback(settings) { const data = JSON.parse( localStorage.getItem(this.getStateSaveKey()) ); - debugger; - if (data) { //Do not save the start value (current page), as we want to always start at the first page on a page reload delete data.start; diff --git a/assets/js/lib/datatables.js b/assets/js/lib/datatables.js index 5c94799a..99675ae1 100644 --- a/assets/js/lib/datatables.js +++ b/assets/js/lib/datatables.js @@ -72,6 +72,17 @@ } } else { request._dt = config.name; + + //Try to resolve the original column index when the column was reordered (using the ColReorder plugin) + //Only do this when _ColReorder_iOrigCol is available + if (settings.aoColumns && settings.aoColumns.length && settings.aoColumns[0]._ColReorder_iOrigCol !== undefined) { + if (request.order && request.order.length) { + request.order.forEach(function (order) { + order.column = settings.aoColumns[order.column]._ColReorder_iOrigCol; + }); + } + } + $.ajax(typeof config.url === 'function' ? config.url(dt) : config.url, { method: config.method, data: request