Deleting a row from the table... table is not empty

Deleting a row from the table... table is not empty

foimystfoimyst Posts: 10Questions: 0Answers: 0
edited March 2010 in General
I made two tables transferring row from one data to another by clicking the image

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

/* Add a click handler to the rows - this could be used as a callback */

$('#searchTable td img.button').click(function(){

var index = $(this).parent().parent().parent().children().index($(this).parent().parent());
var row = sTable .fnGetNodes( index );
sTable.fnDeleteRow( index );
$('#preferTable > tbody:last').append(row);

} );

sTable = $('#searchTable').dataTable( );
pTable = $('#preferTable').dataTable( );

});

[/code]

The my dummy has only two data... the problem is when I delete index 1 then index 0, table is empty which is correct... But when I delete index 0 then index 0, the latest row is not deleted nor transfered...

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Are you sure that 'row' is the TR element you want? I'm not sure that 'index' is the value you are expecting it to be. You are passing in the visible index (which takes account of sorting) rather than the internal cache index, which DataTables is expecting.

    To make it easier, I'd suggest just passing in the TR element (drop the index stuff). Then use fnGetData, to get the data for that row, and then fnAddData to add it to the other table, and fnDeleteRow on the original table to delete it.

    Allan
  • foimystfoimyst Posts: 10Questions: 0Answers: 0
    edited March 2010
    Can you give an examples or the answer to my question cause i dont get it... sorry but im not that good like talkativewizard that automatically gets what you said... Sorry for being stupid...

    Tried this... havent tested due to the fact that oSettings.aoData[iRow] is undefined

    [code]
    $('#searchTable td img.movebut').click(function(){
    var row = sTable.fnGetData($(this).parent().parent());
    sTable.fnDeleteRow( row ); --> havent tested
    pTable.fnAddRow( row ); --> havent tested
    } );
    [/code]
  • foimystfoimyst Posts: 10Questions: 0Answers: 0
    I think I understand a little on what should I do.... so I come up of this code...

    [code]
    $(document).ready(function() {
    $('#searchTable td img.movebut').click(function(){
    var oRow = $(this).parent().parent();
    var row = sTable.fnGetData(oRow[0]);
    sTable.fnDeleteRow(row);
    $('#preferTable > tbody:last').append(row);
    } );

    sTable = $('#searchTable').dataTable( );
    pTable = $('#preferTable').dataTable( );

    });
    [/code]

    But same thing... Either oSettings.aoData[iRow] or oSettings.aoData[iAODataIndex] is undefined
This discussion has been closed.