I have datatables 1.10 on a page. There is an option to copy a line from the table and then paste that line in another place. This is done by checking the selected lines. So, my problem comes in when I redraw the grid.
redrawGrid: function (position, newLine) {
alert(newLine.linenbr)
var tbl = $("#list").DataTable();
var curData = tbl.rows().data();
curData.splice(position, 0, newLine);
console.log(curData);
for (var ndx = 0; ndx < curData.length; ndx++) {
alert(curData[ndx].descr)
curData[ndx].linenbr = ndx + 1;
console.log(curData[ndx].linenbr);
}
console.log(curData)
tbl.clear();
tbl.rows.add(curData);
tbl.draw();
},
The above is the function in which my issue arises. I pass in the position in which the line should be pasted. It is the correct position. I pass in the data associated with the copied line. It is correct. On the console.log just before I clear the table, everything looks perfect as long as I create an error or something so that the table doesn't clear and redraw. If the table redraws, then the new line isn't pasted where it should be. Instead, it is pasted right below the original line from which it has been copied. In my for loop, you can see where I alert with the description as well as write the linenbr property to the console. At that point, those are correct. However, if I let the table redraw, the linenbr, which is what I am sorting the table by, changes to a number that corresponds with next sequential number after the original linenbr from which this line was copied. Can someone tell me what I am doing wrong with this? Thanks for any and all help.