fnDeleteROW bug
fnDeleteROW bug
dawidmal22
Posts: 1Questions: 0Answers: 0
During erasing a row when you do it first it deletes the row that you wanted but if i delete another row in the same time (withour rerfeshing page ) it deletes different row.
For example we have 5 rows
1
2
3
4
5
I delete 4 is fine
deleting 3 in same time without refreshing - row 3 it deletes 1 or 2 i cant say which one.
For example we have 5 rows
1
2
3
4
5
I delete 4 is fine
deleting 3 in same time without refreshing - row 3 it deletes 1 or 2 i cant say which one.
This discussion has been closed.
Replies
I've created the 'Actions' column dynamically and inserted 'Delete' icon, and passing the table index.
Script I m using to create the table and column:
[code]
(function () {
App = {};
// delete the row
App.deleteRow = function (index, dbId) {
if(confirm('Do you want to delete: ' + dbId)) {
if(deleteRecordAtServer()) { // make server request
jqdt.fnDeleteRow(index, function (dtSettings, row) {
console.log('Row deleted');
}, true);
}
}
};
var renderActions = function (idCol) {
var id = idCol.aData.id; // get the id
return '';
}
$.fn.dataTableExt.sErrMode = 'throw';
jqdt = $('#dataTable').dataTable( {
bJQueryUI: true,
sPaginationType: 'full_numbers',
aaData: testdata.records,
aoColumns: [
{ mDataProp: 'name', sTitle: 'Name' },
{ mDataProp: 'name', sTitle: 'Name' },
{ mDataProp: 'id', bSortable: false, sWidth: 'auto',
sTitle: 'Actions', fnRender: renderActions }
]
} );
}());
[/code]
And, the test data is:
[code]
testdata = {
"records": [
{"id": "1", "name": "Record 1" },
{"id": "2", "name": "Record 2" },
{"id": "3", "name": "Record 3" },
{"id": "4", "name": "Record 4" },
{"id": "5", "name": "Record 5" }
]
}
[/code]
When I delete for first time (some times, for second time too) correct row is getting deleted. But from then on, some random row is getting deleted.
Is this a bug or will indexes change when a row is deleted? if indexes are changed again, then we've a problem with the 'Delete' link generation!
Thanks,
ManiKanta
Workaround for that is using the cell () node. It is discussed in http://www.datatables.net/forums/discussion/6309/solved-fndeleterow-deleting-wrong-rows#Item_2
after deleting one item, if you don't update your rendered links (refresh the page/table), your row ID's will no longer match for some of the rows.