Disclaimer: This is slightly mind-boggling, it's been a long night and I'm not a native speaker - so pls. forgive if the description is unclear. Pls. just comment and I'll try to clarify :)
I am trying to make a Datatables-table editable, and so far it looks quite good. But I got a surprise when I looked at the results in detail and it turned out that my little function to clone a row also modified the original row!
for a repro, pls. have a look at the saved page which I stored @ http://mbaas.de/edperm.html. Open the console, click on the "speichern"-Button: this will just log the data to the console. (Just to make sure the values are what we expect). Now click on the small icon to the left of the "7" in the last row: this is supposed to clone that row (JS-Function cloneRow
which I'll show later) and watch the console-output: check the array that is printed immediately after "cloneRow!" - as you see in the code, nothing has been done to update data, yet data[3][0] has been changed already! And, BTW, line3 should be totally unaffected anyway by this update - I want to read that row, change the id and append it.
So, here is the code of cloneRow:
function cloneRow(arg)
{
var oTable = $("#tabPerm").DataTable();
console.log('cloneRow!');
var d1a = oTable.data();
console.log(d1a);
arg=$(arg).closest('tr');
var d = oTable.row(arg).data();
console.log("Vor Zuweisung d");
var d2a = oTable.data();
console.log(d2a);
d[0]=-7;
console.log("Nach Zuweisung d");
var d3a = oTable.data();
console.log(d3a);
oTable.row.add(d).draw();
var d4a = oTable.data();
console.log(d4a);
}
What is the explanation of this effect? Is it timing of console-output or what...?