Question about possible fnDeleteRow bug
Question about possible fnDeleteRow bug
rwillmer
Posts: 10Questions: 1Answers: 0
I have a problem which looks to me like a bug. But I'm a DataTables newbie, so am a bit unsure how it's supposed to work.
If you could confirm that my understanding of how it's supposed to work is correct, I'll put together a test case to demonstrate it.
I'm using datatables 1.9.4:
- Bootstrap v2
- data loaded via Ajax
- sorting enabled
- pagination style is 'bootstrap'
The problem I'm seeing is this: if I just wanted a read-only table, it's all working splendidly. But I have a button on each row which, when pressed, will delete the row.
The code to delete the row on the backed works fine; but I'm trying to delete the row on the client-side table, so I don't have to reload the whole table from Ajax.
I'm finding the correct row, and passing that to fnDeleteRow. And *a* row is being deleted, but not the correct one.
What I think is happening is this:
fnDeleteRow expects the row to have _DT_RowIndex set to be the index of the visible rows, whereas it's staying as the index of the rows when initially read from Ajax.
I can see from inside the debugger, that for example, the row I've selected was the 4th row returned in the Ajax data; but after sorting, it's the 6th row in the displayed table.
and _DT_RowIndex is set to 4, whereas I think it should now be set to 6.
So when this row is passed to fnDeleteRow, the displayed row 4 is deleted, not the actual row 6 selected.
If this sounds wrong (i.e. I've understood what's happened and the behaviour is incorrect, as I suspect), then I'll produce a test case.
thanks
Rachel
If you could confirm that my understanding of how it's supposed to work is correct, I'll put together a test case to demonstrate it.
I'm using datatables 1.9.4:
- Bootstrap v2
- data loaded via Ajax
- sorting enabled
- pagination style is 'bootstrap'
The problem I'm seeing is this: if I just wanted a read-only table, it's all working splendidly. But I have a button on each row which, when pressed, will delete the row.
The code to delete the row on the backed works fine; but I'm trying to delete the row on the client-side table, so I don't have to reload the whole table from Ajax.
I'm finding the correct row, and passing that to fnDeleteRow. And *a* row is being deleted, but not the correct one.
What I think is happening is this:
fnDeleteRow expects the row to have _DT_RowIndex set to be the index of the visible rows, whereas it's staying as the index of the rows when initially read from Ajax.
I can see from inside the debugger, that for example, the row I've selected was the 4th row returned in the Ajax data; but after sorting, it's the 6th row in the displayed table.
and _DT_RowIndex is set to 4, whereas I think it should now be set to 6.
So when this row is passed to fnDeleteRow, the displayed row 4 is deleted, not the actual row 6 selected.
If this sounds wrong (i.e. I've understood what's happened and the behaviour is incorrect, as I suspect), then I'll produce a test case.
thanks
Rachel
This discussion has been closed.
Replies
I'd imagine you are passing an index in then - not a TR element, which I would very much encourage you to do. When fnDeleteRow is given an index it uses the internal indexing, about which you should really need to know nothing :-). The same applies to _DT_RowIndex - its an internal variable.
Allan
I'll make a test case to show you what I mean.
I've posted this to the bug reports forum; perhaps best to add any comments there?
Unless of course I've done something blindingly stupid and this isn't a bug :)
Allan
Rachel
P.S. I'm very very impressed with getting a response that quickly on Xmas Eve! :)