Getting table data in "preDrawCallback"

Getting table data in "preDrawCallback"

MirMir Posts: 27Questions: 7Answers: 1

I need to get data before it is rendered on the table. My requirement is to have rows in table equal to selected length (10, 15, 25). So I need to add empty data to create the filler rows. Could anyone please help me read table data in "preDrawCallback".

I have done that using "drawCallback", where I get the <tr>s & <td>s but that is causing the scrollbar appear after header resizes. In brief it is causing header alignment issues.

So I need to read & manipulate data before it constructs <tr> & <td>s in "preDrawCallback".

Answers

  • MirMir Posts: 27Questions: 7Answers: 1

    Can anyone please help be get table data in "preDrawCallback" before rendering.

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    Based on your goal, surely you want to use drawCallback (i.e. after the table has been drawn) so you can insert the additional rows required? Rows added when using preDrawCallback will just be removed by DataTables.

    To do that you would just use standard jQuery methods - i.e. get the number of rows currently in the table $('#myTable tbody tr').length then calculate how many rows you need to create and insert them.

    It sounds like you might have the scrolling options enabled. If so, disable them or at least try removing scrollCollapse (I don't know if you are using that or not as you haven't provided a test case, as required in the forum rules).

    Allan

This discussion has been closed.