Callback after table is drawn?

Callback after table is drawn?

chrisrbloomchrisrbloom Posts: 8Questions: 3Answers: 0

Is there a callback that I can call after the table is drawn and completely done?

I'm using an ajax data source.

In my columns declaration, I'm using the "render" option to render

<

div> tags with specific classes.

I then have event listeners that attach to those classes so that I can do additional stuff (like open a modal, expand children, etc).

when I set my 'initComplete' option function to look for all of my specific classes, it can't find any because they aren't drawn yet.

I'm just looking for a "everything's done" event. Anyone?

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Maybe

    $('#example').on( 'draw.dt', function () {
    

    https://datatables.net/reference/event/draw

  • chrisrbloomchrisrbloom Posts: 8Questions: 3Answers: 0

    thanks for the reply. Draw actually fires before the initComplete event.

  • chrisrbloomchrisrbloom Posts: 8Questions: 3Answers: 0

    my bad..it does actually fire after initComplete, but still not before I can attach anything to a dom element.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    initComplete executes once the Datatable has completed initialization. If the classes aren't there then maybe the column render is not right. Are you attaching the listeners form within initComplete? You may need to move them there.

    Maybe you can post a test case using one of the AJAX loaded JS BIN templates:
    https://datatables.net/manual/tech-notes/9#Ajax-loaded-data

    Kevin

  • chrisrbloomchrisrbloom Posts: 8Questions: 3Answers: 0
    edited August 2017

    Thanks Kevin - yes, I'm calling the listener functions from within the initComplete option.

    When I open up the console after the page is rendered I can call the listener functions and they attach fine.

    that's why I was thinking initComplete wasn't firing as late as I wanted.

    I'll see if I can work up an example.

This discussion has been closed.