Skip to content

Commit

Permalink
Fix: ColReorder would throw an error after a row had been deleted
Browse files Browse the repository at this point in the history
Error occurred due to not correctly handling DataTables 2's sparse array

https://datatables.net/forums/discussion/78930
  • Loading branch information
AllanJard committed May 7, 2024
1 parent 0cd1674 commit 23fb4c6
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions js/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,31 @@ export function move(dt: Api, from: number[], to: number): void {
// Per row manipulations
for (i = 0; i < settings.aoData.length; i++) {
var data = settings.aoData[i];

// Allow for sparse array
if (! data) {
continue;
}

var cells = data.anCells;

if (cells) {
// Array of cells
arrayMove(cells, from[0], from.length, to);
// Not yet rendered
if (! cells) {
continue;
}

// Array of cells
arrayMove(cells, from[0], from.length, to);

for (j = 0; j < cells.length; j++) {
// Reinsert into the document in the new order
if (data.nTr && cells[j] && columns[j].bVisible) {
data.nTr.appendChild(cells[j]);
}
for (j = 0; j < cells.length; j++) {
// Reinsert into the document in the new order
if (data.nTr && cells[j] && columns[j].bVisible) {
data.nTr.appendChild(cells[j]);
}

// Update lookup index
if (cells[j] && cells[j]._DT_CellIndex) {
cells[j]._DT_CellIndex.column = j;
}
// Update lookup index
if (cells[j] && cells[j]._DT_CellIndex) {
cells[j]._DT_CellIndex.column = j;
}
}
}
Expand Down

0 comments on commit 23fb4c6

Please sign in to comment.