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.