DataTable AMD initialization callback
DataTable AMD initialization callback
Mojimi
Posts: 4Questions: 2Answers: 0
For example, how can I achieve this form of callback in DataTable?
There are several things I need to do on the DataTable object once its loaded the data, but the initComplete callback does not returns the DataTable itself...
The Draw event wouldn't be ideal as it would fire on sorting, etc...
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Are you trying to access the Datatables API in the initComplete callback?
If so you can use this
$('#example').DataTable()
. For example to get the row count you can use this in initComplete:$('#example').DataTable().rows().count()
Kevin
Yes that does it thanks.
I personally find it weird that an on load event does not return said loaded object...
initComplete
is still part of theDataTable()
function. Once the function is done, ie, after initCompete, the function will return an API instance In your case this will be in thedtable
variable. Outside of theDataTable()
function you can access the API usingdtable
.Kevin
With this form of initialisation, the
$().DataTable()
call is synchronous - i.e. the$().DataTable()
call hasn't finished being executed wheninitComplete
executes, hence whydtable
is still undefined.Using the context of the callback as Kevin suggested is the right way to do it.
Allan