Rowreorder with unordered sequence... Part2
Rowreorder with unordered sequence... Part2
Hello,
What I would like to do is have a table which the user can order columns (asc/desc), and still retain rowreoder functionality. Various attempts at this suggest using a (perhaps) hidden column to retain a sequence. I took a look at this example[1], cloned it and produced a jsfiddle of it here[2]. Now the table works as I expect, however, if I were to loop over the table rows after reordering, I do not get the data I see on the screen for each row.
[1] https://datatables.net/forums/discussion/46889/row-reordering-after-sorting
[2] http://live.datatables.net/hifomuqa/29/edit
For example, from the jsfiddle upon loading, if I type $("#example").DataTable().row(0).data()
into the console, I get:
[object Object] {
#: 1,
addToGeneration: "<button type='button' class='table-button' id='1'>Add</button>",
category: "Fruits",
description: "<button type='button' class='table-button' id='1'>Description</button>",
name: "Apple",
sequence: 1,
size: "small",
unit: "pcs"
}
However, swap Apple and Boeing, the above call returns:
[object Object] {
#: 2,
addToGeneration: "<button type='button' class='table-button' id='1'>Add</button>",
category: "Fruits",
description: "<button type='button' class='table-button' id='1'>Description</button>",
name: "Apple",
sequence: 2,
size: "small",
unit: "pcs"
}
It looks like the underlying table row/cell cache is not being updated. I tried putting rows().invalidate() in various places, but it doesn't seem to update the underlying cache.
I could add a class to each row, and use a standard jQuery selector to extract the information I want from the DOM elements, but given my existing code uses the API, is there something I'm missing?
Many thanks...
Stacy.
Answers
Using
row(0)
is the original row index, ie, it doesn't change due to ordering. It is working as expected. Please see this thread for more info:https://datatables.net/forums/discussion/comment/139856/#Comment_139856
There are some examples here:
https://datatables.net/reference/type/row-selector#jQuery
Updated the example to show a comparison of
row(0)
androw(':eq(0)')
after the table has been reordered.http://live.datatables.net/giqofixo/1/edit
Kevin