Child Rows do not export to Excel in applied sort order
Child Rows do not export to Excel in applied sort order
Hello! I've adopted Kevin's Child Row Export code from the thread referenced below, but found that child table rows are not exported in the applied sort order.
- In this test case, the default order is descending by "AR Total".
- When expanding child table, you can see the current order of the parent table is successfully applied to the child table.
- When exporting to Excel, however, the child table order is the same as its load order (in production, child data arrives with an ajax call).
I thought this might be handled in the childTable For loop...
// The child data is an array of rows
for (c = 0; c < childTable.rows().count(); c++) {
// Get row data.
rowData = childTable.row(c, { order: "applied"}).data();
// order is specified as applied, yet initial order is used instead.
but it doesn't make a difference
Here's the thread discussing the child row export:
https://datatables.net/forums/discussion/comment/160693
Here's the test case:
https://live.datatables.net/toguvute/1/edit
Thanks!
This question has an accepted answers - jump to answer
Answers
Clever solution, took me a minute to figure out what you are doing
This is a tricky one. You are passing an index to the
row()
API. The row index is set during initial load of the Datatable data and does not change. Passing index 0, for example, will choose the same row no matter how the table is sorted.You will need to use
rows().data()
with theselector-modifier
of{order: "applied"}
to get all the rows in order. I added the following to your test case:You will need to iterate over
allRows
to get the applied order. Instead of this:Kevin
Very helpful, sir! Using the
rows().data()
API was indeed the answer.