init.dt is not fired before the first xhr event

init.dt is not fired before the first xhr event

ZxurianZxurian Posts: 26Questions: 6Answers: 0

http://live.datatables.net/juqudeji/1/edit?html,css,js,console,output

though the ajax won't work, you can see the events being initialized, and the first output is "two", not "one". my local code isn't working because of this issue.

init.dt is defined as "Initialisation complete event - fired when DataTables has been fully initialised."
Shouldn't this event fire before the first ajax request is sent?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin
    Answer ✓

    This event ordering (xhr before init) is correct since init is triggered after the table has been fully initialised and the first draw of data complete (i.e. the data must have been loaded via Ajax is that is how it is coming in). I'll add a note to the documentation to address that.

    Allan

  • ZxurianZxurian Posts: 26Questions: 6Answers: 0

    in that case, is there any event that I can hook into to add the dom elements into the correct div? or is there a way to rewrite the template that is populated by datatables elements?

    I'm currently using 'dom': '<"#div_bookquestHeaderRow"lf><"bookquestPagination"ip>tr<"bookquestPagination"ip>', to put the length & filter into their own div, but due to styling, as well as additional filtering, need to add some other elements into that div as well.

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin

    You could just add that code immediately after you initialise the table could you not? There is no callback that signals the start of an initialisation at the moment.

    Allan

  • ZxurianZxurian Posts: 26Questions: 6Answers: 0

    http://puu.sh/ec9sH/de8225f12d.png

    the Show Licensed / Canceled are dom elements that I'm trying to add. When the ajax event fires, it uses values from those checkboxes as part of the filtering sent to the server. I'm running into a problem as I'm trying to preset those based on the url, and since there not there the first time the xhr event fires, then they're not sent as part of the filter.

    Is there anyway I can
    a) push dataTable dom elements into pre-existing divs? (ie, if #div_bookquestHeaderRow already existed within the dom at the time datatable initialized, and it could insert the length & filter elements into it)
    b) Have the firxt xhr event not fire when Datatable is first initialized, thus it'll still be setup for it, and instead I can put a manual .api().ajax.reload() at the end of the init.dt event
    ?

  • allanallan Posts: 61,880Questions: 1Answers: 10,139 Site admin
    Answer ✓

    Is there anyway I can a) push dataTable dom elements into pre-existing divs? (ie, if #div_bookquestHeaderRow already existed within the dom at the time datatable initialized, and it could insert the length & filter elements into

    You would need to use a bit of jQuery to do that. There isn't a built in way of doing it.

    b) Have the firxt xhr event not fire when Datatable is first initialized

    No, but you could either ignore the first one or not bind your event handler until init is fired.

    Allan

  • ZxurianZxurian Posts: 26Questions: 6Answers: 0

    hm.... thanks for the update. It sounds like there isn't a clean way to do it out of the gate.

    with the jQuery & some timing I achieved the effect with your first suggestion.

This discussion has been closed.