Event after initial load

Event after initial load

StanAccyStanAccy Posts: 31Questions: 5Answers: 0
edited October 2014 in Free community support

Is there an event that fires after the Datatable has loaded its initial state (first page of data, applied extra widgets etc)?

While I can register and see events for Redraw, Paging, destroy, I expected the init event to fire after the initial page load, but its not - in fact I cant get the init event to fire at all.

I have two questions:

  1. If I want to run some javascript on the contents of the table after its initial draw, and after every redraw / page, where's the best place to do this?
  2. Is it possible to access the ID of the outermost wrapper element that Datatables adds?

Thanks

Nick

Using Datatables 1.10.0 / 1.10.3

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Yes - init.

    If ou can't get it to work, please link to a test case showing the issue.

    and after every redraw / page, where's the best place to do this?

    Use draw or drawCallback.

    Is it possible to access the ID of the outermost wrapper element that Datatables adds?

    Use table().container() to get the node and then just read its id.

    Allan

  • StanAccyStanAccy Posts: 31Questions: 5Answers: 0

    Thanks Allan. I double checked what I was doing - I'd applied the .on() call after the call to .dataTable() so the event was never captured.

    With regards to these .on() events, do I have to clean them up when the Datatable is being destroyed? (including the destroy event handler)

  • StanAccyStanAccy Posts: 31Questions: 5Answers: 0

    Quick followup on the table.container() - is the example shown here: http://datatables.net/reference/api/table().container() correct?

    The first line gets a variable called 'table' but the second line doesnt reference it (I think). Is there a typo or have I misunderstood the javascript?

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    I'd applied the .on() call after the call to .dataTable() so the event was never captured.

    You need to use the dt namespace in that case, as noted in the events documentation.

    The first line gets a variable called 'table' but the second line doesnt reference it (I think). Is there a typo or have I misunderstood the javascript?

    Typo - it should be:

    var table = $('#example').DataTable();
     
    $( table.table().container() )
        .addClass( 'selectable' );
    

    I'll fix it on Monday!

    Allan

  • StanAccyStanAccy Posts: 31Questions: 5Answers: 0

    Thanks Allan. With regards to the dt namespace - what does this mean with respect to jquery events - could you add an example to the page please? (Javascript is not my primary dev language)

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Example showing use of the .dt namespace: http://live.datatables.net/nacakahu/1/edit .

    Allan

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Fix committed here.

    Thanks!
    Allan

This discussion has been closed.