fnDeleteRow - error when only one row exists

fnDeleteRow - error when only one row exists

andrianoidandrianoid Posts: 1Questions: 0Answers: 0
edited July 2011 in Bug reports
Hello,

I'm having this error when running through batches of items. I have a 'batch process' function that looks at each row, does some processing, updates the record and then deletes it from the table (using fnDeleteRow). fnDeleteRow works each time except for the last row... when it tries to delete the row, i get: "Line: 58 - Error: 'nTr' is null or not an object". This is also true if the table only had one row to begin with. Here's the code:

[code]
function updater_update_dnu(button,followup){
var row = $(button).parent().parent();
var audit_id = button.attr("id");
if(followup){
///set as followup and add notes
//////////////////////////
//do processing
$.post("ajax/RecordAuditFollowup",{
audit_id:audit_id,
action: "followup"
},function(data){
upTable.fnDeleteRow(row,null,true);
// upTable.fnDraw();
},'json');
} else {
///just set as complete.
//////////////////////////
//do processing
$.post("ajax/RecordAuditComplete",{
audit_id:audit_id,
action: "complete"
},function(data){
if ($(".audit_item").length > 1) {
upTable.fnDeleteRow(row, null, true);
} else {
$("#updater_table_dnu tbody").html("");
}
// upTable.fnDraw();
},'json');
}
}
[/code]

I have a workaround as seen above, where if there is only one row remaining i clear the contents of tbody instead of deleting the row, but this is neither elegant nor fully effective (if any filtering functions are used, that row re-draws).

Am i crazy? Should I be doing something different or is this a bug?

-Andrian

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I've just tested this and fnDeleteRow works fine on the last row in the table. First thing to check is if you are using the latest version of DataTables? If not that, then I'd suggest console.log( row ) be added to the code to check that it is the TR node you expect and failing that, can you link us to an example of it not working please.

    Allan
  • NirNir Posts: 4Questions: 0Answers: 0
    same problem here. the TR won't get deleted if there is only 1 row in the table (v1.8.1+colreorderwithresize)
    tested on both IE8 and firefox.

    the error is as following:

    Error: aoData is undefined
    Source File: http://127.0.0.1/js/jquery.dataTables.js
    Line: 3243
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Could you link to a page which is showing the error please? As I noted before, I was unable to reproduce this issue so a demo of it would be exceptionally useful.

    Thanks,
    Allan
  • NirNir Posts: 4Questions: 0Answers: 0
    Allan,
    Please find this simplified example:
    http://doar-rashum.co.il/test_tables

    it actually appears to be trying to delete the wrong row.
  • bubuzzzbubuzzz Posts: 26Questions: 0Answers: 0
    edited August 2011
    from my experience, dont use fnDeleteRow (). Just send the id back to server to delete record and then use fnDraw () to re draw the table

    You can see my problem in here http://datatables.net/forums/discussion/comment/24516
  • NirNir Posts: 4Questions: 0Answers: 0
    Hi,
    How would fnDraw know to omit the deleted row?
    I build the from server side...
    Actually, another solution which I tried to implment is to delete the TR manually, but it yielded some unpredictable behaviours such as deleting two rows at once
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    If you deleted the row on the server side (db), then redraw with fnDraw, the draw will no longer have that row.
  • bubuzzzbubuzzz Posts: 26Questions: 0Answers: 0
    edited August 2011
    @Nir: send the Id back to the server to delete the record, and then use oTable.fnDraw(false). When you send the param false to fnDraw, it will keep the stage of the page. So, in the end, you will have the row deleted "dynamically", and you still stay at the current page

    something like this:
    [code]

    oTable = $.('#example').datatable (function () {
    .....,
    .....,
    .....,
    "fnDrawCallback": function () {
    $.('#example tr td #delete').bind ('click', function (event) {
    event.preventDefault();
    $.get(this.href, {}, function (response) {
    oTable.fnDraw(false);
    }
    });
    },
    .....,
    .....,
    });

    [/code]
  • NirNir Posts: 4Questions: 0Answers: 0
    no, fnDraw(true/false) didn't work either.
    unfortunately the only cure was full refresh of the div -- the whole table.
  • kirky_Dkirky_D Posts: 1Questions: 0Answers: 0
    I was having this exact problem. It turned out I was using a TD element as the argument for fnDeleteRow which for some reason still works on all rows other than the case where there is only row in the table.

    Use console.log() to make sure you are passing the TR element and not a TD
This discussion has been closed.