mleibman/SlickGrid — Issue #300: Example9 row-reordering can corrupt lists
Author: ajrnz
Created: 2012-03-08 11:15:28+00:00
State: open

To reproduce. Add 12 items to the grid. Select items 8,9,10, Move to above position 7. The list will in grow by one item.

This is a problem in onMoveRows and is due to lexical instead of numeric sorting. In the example above row 10 will be sorted before 8 & 9 which is a problem for the splices below. The code below corrects the problem. It also fixes a misordering problem when moving multiple rows

...
var insertBefore = args.insertBefore;
left = data.slice(0, insertBefore);
right = data.slice(insertBefore, data.length);

// Put in table order - the selection doesn't guarantee this
rows.sort(function(a,b){return a-b});

for (var i = 0; i < rows.length; i++) {
extractedRows.push(data[rows[i]]);
}

// Need to sort reverse numerically or else the splices below fail badly
rows.reverse();

for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (row < insertBefore) {
left.splice(row, 1);
...