Event after initial load
Event after initial load
StanAccy
Posts: 31Questions: 5Answers: 0
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:
- 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?
- 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
This discussion has been closed.
Answers
Yes -
init
.If ou can't get it to work, please link to a test case showing the issue.
Use
draw
ordrawCallback
.Use
table().container()
to get the node and then just read its id.Allan
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)
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?
You need to use the
dt
namespace in that case, as noted in the events documentation.Typo - it should be:
I'll fix it on Monday!
Allan
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)
Example showing use of the
.dt
namespace: http://live.datatables.net/nacakahu/1/edit .Allan
Fix committed here.
Thanks!
Allan