Event for when a page has been fully loaded

Event for when a page has been fully loaded

jaesunjaesun Posts: 7Questions: 1Answers: 0
edited August 2016 in Free community support

I am looking for an event (if there is one) that fires when a page has been fully loaded (and shows the new page).

I saw the page.dt event (mentioned here https://datatables.net/forums/discussion/7816/is-there-an-event-fired-before-or-after-paging-action)

But the event is fired before the page is loaded.

Example Code:

// DataTables initialization, etc
.on('page.dt', function(e, settings, json) { 
        if (typeof pageDT359 == 'function') { pageDT359(); } 
}

function pageDT359 () {
        alert('hello');
    }

When I go to change the page, it fires the pageDT359() function, then after the alert, it changes the page to the new page.

The same with the draw.dt event.

I am wanting an event that fires AFTER the new page is loaded.

It doesn't seem to be one (https://datatables.net/reference/event/)

If not, any ideas on how to do so? TIA

Answers

  • jmwitherjmwither Posts: 3Questions: 0Answers: 0
  • jaesunjaesun Posts: 7Questions: 1Answers: 0
    edited August 2016

    I already tried it with draw. I get the same result, the event fires before the page is loaded.

  • jaesunjaesun Posts: 7Questions: 1Answers: 0

    Also, I should note, the live example is here:

    http://live.datatables.net/jabojata/1/edit?js,output

    BUT, it won't show the problem since alert() is not allowed on jsfiddle

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    Use init or initCallback.

    Allan

  • jaesunjaesun Posts: 7Questions: 1Answers: 0
    edited August 2016

    Sorry, I should have been more clear in my original explanation.

    I am looking for an event for when the result pages are loaded, not when the full page is loaded. So the WebPage is loaded. It has 200 results and it is listed on 10 pages (20 each page). I am looking for an event for when I change result pages. So I go to page 3 of the results (results 60-80), results are loaded and shown, and THEN the event (if it exists?) is fired.

    Again, sorry for the confusion.

    page and draw events are close to what I need. But page event mentions:

    Note that the page will be fired before the table has been redrawn with the updated data.

    And the draw event is fired afterwards, but before the new table page is shown

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    I am looking for an event for when I change result pages. So I go to page 3 of the results (results 60-80), results are loaded and shown, and THEN the event (if it exists?) is fired.

    draw for that. If it is triggering early, please link to a test case showing the issue.

    Allan

  • jaesunjaesun Posts: 7Questions: 1Answers: 0
    edited September 2016

    http://live.datatables.net/detoyuma/1/edit?html,js,output

    The test case won't run on jsfiddle/live.datatables due to the iframe sandbox restrictions, so would have to run it manually

    This is on DataTables 1.10.11, jquery 2.1.3 (though it looks like I would still get the error in 1.10.12)

    Should also note, this looks to effect anything that fires the draw event. Using the search filter, changing the num results per page, etc. fires the event before showing the updates results.

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    You are attaching the event after the table has already fully initialised and draw the first page.

    Attach it using jQuery before initialising the table: http://live.datatables.net/detoyuma/2/edit

    Allan

  • jaesunjaesun Posts: 7Questions: 1Answers: 0

    Still running into the same issue.

    I copied your code and just changed the console.log to alert

    I did a screen capture

    https://www.youtube.com/watch?v=Kwjm-nFalr4

    As you can see, when I change the page, it still fires early before the new page is shown.

  • jaesunjaesun Posts: 7Questions: 1Answers: 0

    is there anything else I can do to fix the issue?

This discussion has been closed.