Which callback or event to use so that myDataTable.rows() is populated
Which callback or event to use so that myDataTable.rows() is populated
SlowburnAZ
Posts: 14Questions: 2Answers: 0
Hello all,
I'm trying to find out which callback or event to use so that the rows in the table are available to manipulate.
I'm using the "data" option to provide data, but I've tried both the drawCallback
option, the initComplete
option, and even the myDataTable.on('draw', function() {...})
event, but in each one, it seems the rows haven't yet been drawn.
Can anyone help?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
BTW, the
rowCallback
option won't work for me, as I need to have access to all rows at once.When I say "it seems the rows haven't yet been drawn.", I mena that myDataTable.rows() is an empty array.
Your
myDataTable
variable won't be available in any of the callbacks within the Datatables init code, since the Datatables function hasn't returned yet. However you should be able to access the API in eitherdrawCallback
orinitComplete
using something like this:$('#myTable').DataTable().rows();
Kevin
Thanks. What I'm really trying to do is create aggregate rows with totals. Now, there's a plugin for that, and it seems to work... somewhat.
See, that plugin only aggregates the "visible" rows, determined by the "Show ### entries" dropdown. So, if I have 250 rows, and the page size is 50, but 100 of those are in the same "group" (say, location = "Calfiornia" or something), the aggregate row on that page only aggregates for those 50 visible rows in the page, not the 100 total rows that are in the "California" group.
Is there some other way I can do this?
Are you referring to the RowGroup extension? If so then maybe this example will help:
http://live.datatables.net/fazigehi/1/edit
It shows how to total over all the rows using
filter()
,pluck()
and the rows().sum() plugin.Kevin
I'll give that a shot
Kevin,
Is there a way to get these aggregate rows to be included in the various export formats (PDF, Excel, CSV, etc)?
According to the compatibility chart row grouping info is not included in the exports.
Kevin
So, currently there's no way to do this... that's a shame. Would be mighty helpful to have those rows exported as well.