fnDeleteRow issue when deleteing the LAST Row.

fnDeleteRow issue when deleteing the LAST Row.

vonkhadesvonkhades Posts: 1Questions: 0Answers: 0
edited September 2012 in Bug reports
Hi Guys,

Im having an issue when the user deletes the LAST row of a table, that means when the table has only 1 remaining row after deleting all the other rows.

Im using a button-per-row to delete each row, this is the code rendered for when the table has only 1 row remaining.

[code]


2670
Carla xxxxx
xxxx@xxxxxx.co.uk



[/code]

And Im deleting the row with the function
[code]
function remove_row(control){
_row = $(control).parent().parent();
$('#example').dataTable().fnDeleteRow(_row);
}
[/code]

This javascript function works great to remove all other elements of the table, but the last!

Im adding ROWS to that table with the fnAddData function somewhere else in the page which seems to be working just fine:
[code]
$.get('load_rows.php',function(data) {
_rows = jQuery.parseJSON(data);
for (i = 0; i < _rows.length; i++) {
$('#example').dataTable().fnAddData([_rows[i].tsr_id,_rows[i].tsr_name,_rows[i].tsr_email, "" ]);
}
});
[/code]



The exact JS Exception I get is "in TypeError: aoData is undefined" line 1424 of jquery.dataTables.js version 1.9.3

[code]
var aoData = oSettings.aoData[ oSettings.aiDisplay[j] ];
if (aoData.nTr === null )
{
_fnCreateTr( oSettings, oSettings.aiDisplay[j] );
}
[/code]

And its of course because aoData is undefined (thus aoData.nTr is also undefined) and then all its screwed up... I tried to add some validation like:
[code]
var aoData = oSettings.aoData[ oSettings.aiDisplay[j] ];
if (aoData === undefined || aoData.nTr === null )
{
_fnCreateTr( oSettings, oSettings.aiDisplay[j] );
}
[/code]
but then I get similar errors on _fnCreateTr in line 1073:
[code]
if ( oData.nTr === null )
[/code]


Any idea how I could further debug/fix this problem???


MANY THANKS!!!!

edit:moved to BUGS report.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Could you possible link us to a test page that shows the problem please?

    This test case shows the last row being deleted from a table immediately and working okay: http://live.datatables.net/opibey/edit#javascript,html

    Allan
  • ArvinArvin Posts: 1Questions: 0Answers: 0
    Adding "[0]" after parent() will solve your problem.

    function remove_row(control){
    _row = $(control).parent().parent()[0];
    $('#example').dataTable().fnDeleteRow(_row);
    }

    Arvin
This discussion has been closed.