Which callback or event to use so that myDataTable.rows() is populated

Which callback or event to use so that myDataTable.rows() is populated

SlowburnAZSlowburnAZ 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:

Answers

  • SlowburnAZSlowburnAZ Posts: 14Questions: 2Answers: 0

    BTW, the rowCallback option won't work for me, as I need to have access to all rows at once.

  • SlowburnAZSlowburnAZ Posts: 14Questions: 2Answers: 0

    When I say "it seems the rows haven't yet been drawn.", I mena that myDataTable.rows() is an empty array.

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    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 either drawCallback or initComplete using something like this:
    $('#myTable').DataTable().rows();

    Kevin

  • SlowburnAZSlowburnAZ Posts: 14Questions: 2Answers: 0
    edited February 2018

    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?

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946
    Answer ✓

    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

  • SlowburnAZSlowburnAZ Posts: 14Questions: 2Answers: 0

    I'll give that a shot

  • SlowburnAZSlowburnAZ Posts: 14Questions: 2Answers: 0

    Kevin,

    Is there a way to get these aggregate rows to be included in the various export formats (PDF, Excel, CSV, etc)?

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946
    Answer ✓

    According to the compatibility chart row grouping info is not included in the exports.

    Kevin

  • SlowburnAZSlowburnAZ Posts: 14Questions: 2Answers: 0

    So, currently there's no way to do this... that's a shame. Would be mighty helpful to have those rows exported as well.

This discussion has been closed.