Transfering rows to/from tables; index preservation?

Transfering rows to/from tables; index preservation?

smadersmader Posts: 21Questions: 6Answers: 0
edited November 2013 in DataTables 1.9
Hi all,
Rank beginner here. I have two tables and I would like to transfer rows between then. The code below does this, mostly...
Say I click on the first row of availTable and transfer it to execTable, okay that is fine. However, should I want to transfer the row in execTable back to availTable, the "Field" name is duplicated! This seems to be an indexing issue, since when I transfer the first row (index 0) from availTable to execTable, it has index 0 in the latter. When I transfer that back to availTable, it takes on values for the existing index. I hope this makes sense. I'm not sure how to address it. Any suggestions?

Using DataTables 1.9.4.

[code]
$(document).ready(function() {

availTable = $('#available').dataTable( {
"bProcessing": true,
"bAutoWidth": true,
"aaData": [
[ "BETA", "F1" ],
[ "BETA", "F2" ],
[ "BETA", "F3" ],
[ "BETA", "F4" ]
],
"aoColumns": [
{ "sTitle": "Project" },
{ "sTitle": "Field" },
]
});

execTable = $('#execute').dataTable({
"bProcessing": true,
"bAutoWidth": true,
"aaData": [ ],
"aoColumns": [
{ "sTitle": "Project" },
{ "sTitle": "Field" },
]
});


availTable.on('click','tr',function() {
var data = availTable.fnGetData(this);
execTable.fnAddData(data);
availTable.fnDeleteRow(this);
});

execTable.on('click','tr',function() {
var data = availTable.fnGetData(this);
availTable.fnAddData(data);
execTable.fnDeleteRow(this);
});

});

[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    What do you mean by "index" ? The DataTables internal index? It doesn't appear from the code that you are using that (not that you would want to!).

    Allan
  • smadersmader Posts: 21Questions: 6Answers: 0
    Sorry, I was using the table row position as an index, starting from 0 :)
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    The problem with that is that the sorting will effect the indexing. If you have different sorting on each table, then all bets are off :-)

    Allan
This discussion has been closed.