fnDeleteRow - error when only one row exists
fnDeleteRow - error when only one row exists
andrianoid
Posts: 1Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
Allan
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
Thanks,
Allan
Please find this simplified example:
http://doar-rashum.co.il/test_tables
it actually appears to be trying to delete the wrong row.
You can see my problem in here http://datatables.net/forums/discussion/comment/24516
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
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]
unfortunately the only cure was full refresh of the div -- the whole table.
Use console.log() to make sure you are passing the TR element and not a TD