Skip to content

Commit

Permalink
Fix ordering of columns whose position was changed using colReorder p…
Browse files Browse the repository at this point in the history
…lugin

The colReorder plugin allows to change the position of columns in the datatable. However this changes the column index which does not match the backend index anymore. That caused that the wrong column were ordered in the backend. With this commit the original index will be put in the request, so always the correct coumn is ordered.
  • Loading branch information
jbtronics committed Jul 8, 2023
1 parent 031d134 commit 7574907
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Resources/public/js/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,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
Expand Down

0 comments on commit 7574907

Please sign in to comment.