Question about possible fnDeleteRow bug

Question about possible fnDeleteRow bug

rwillmerrwillmer Posts: 10Questions: 1Answers: 0
edited December 2012 in DataTables 1.9
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

Replies

  • rwillmerrwillmer Posts: 10Questions: 1Answers: 0
    And if this is a bug, is it possible to use jsfiddle.net or similar to provide the ajax data for the test case? or will I need to expose my own server to do that? Any pointers welcome...
  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    > And *a* row is being deleted, but not the correct one.

    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
  • rwillmerrwillmer Posts: 10Questions: 1Answers: 0
    I've tried passing in all variations I can think of; the tr element, the index. The result appears to be the same, the wrong row is deleted.

    I'll make a test case to show you what I mean.
  • rwillmerrwillmer Posts: 10Questions: 1Answers: 0
    I've put a testcase up at http://hobthross.com/watchlist/testcase.

    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 :)
  • allanallan Posts: 63,389Questions: 1Answers: 10,450 Site admin
    Try: `oTable.fnDeleteRow(tr[0]);` . You are currently passing in a jQuery object which is not currently supported (it will be in 1.10).

    Allan
  • rwillmerrwillmer Posts: 10Questions: 1Answers: 0
    Spot on! Thanks!

    Rachel

    P.S. I'm very very impressed with getting a response that quickly on Xmas Eve! :)
This discussion has been closed.