I have created a function to swap rows in a table, but it doesn't seem to be working correctly. The data for the rows doesn't seem to be matching up with the data that is in the array. Can anyone help point out the bug in my code, or how I may be misusing some of the DataTable functions?
function swapDataTableRows(selector, row1Index, row2Index)
{
var datatable = selector.DataTable();
var rows = datatable.rows().data();
var row1Data = datatable.row(row1Index).data();
var row2Data = datatable.row(row2Index).data();
datatable.row(row1Index).data(row2Data);
datatable.row(row2Index).data(row1Data);
}
swapDataTableRows(table, 2, 3) - It will swap rows 1 and 2. If I add 1 to the indexes then it goes out of bounds.
I'm not sure to have understood your problem...
I try to create a simple demo to understand:
http://jsfiddle.net/q0zb1rkc/
... in your functions you never draw the table with new (edited) data:
I change this 2 rows of your script:
datatable.row(row1Index).data(row2Data);
datatable.row(row2Index).data(row1Data);
and i add .draw():
datatable.row(row1Index).data(row2Data);
datatable.row(row2Index).data(row1Data);
width .draw() also DOM change and the ROW1 and ROW2 exchange.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With