Unable to navigate to a specific page

Unable to navigate to a specific page

parsonsparsonsparsonsparsons Posts: 29Questions: 8Answers: 0

This seems pretty cut and dry but it isn't working. Using the API below:

https://datatables.net/reference/api/page()

I have an input button with a jquery on click event, just copy /pasted the code:

table.page('next').draw('page');

I have already init'ed table as my DataTable(). When I click the button, nothing happens, any ideas?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765

    When I click the button, nothing happens, any ideas?

    Please provide a link to your page or a test case replicating the issue so we can see what you have.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Otherwise you will need to verify if your click event is working and if you have any errors in your browser's console.

    Kevin

  • parsonsparsonsparsonsparsons Posts: 29Questions: 8Answers: 0

    After running it through the fiddler it appears to work only if I have it inside document.ready()

    I had it inside that in my code however the DOM must not have been updated, if I put it in:

    $(document).off("click", "#movepage").on("click", "#movepage", function () {

    It now works. Only issue at this point is I don't want it to happen on a mouse click, I want it to just navigate to a page when the table is loaded.

  • kthorngrenkthorngren Posts: 20,277Questions: 26Answers: 4,765
    Answer ✓

    I want it to just navigate to a page when the table is loaded.

    Use initComplete to perform actions after the Datatable has been loaded.

    Kevin

  • parsonsparsonsparsonsparsons Posts: 29Questions: 8Answers: 0

    Thanks I tried that earlier but it wasn't working, turns out i was looking at the wrong function.

  • parsonsparsonsparsonsparsons Posts: 29Questions: 8Answers: 0

    Is there a way for me to reference the table itself during initcomplete? Using the variable name (table) or this is not working.

  • parsonsparsonsparsonsparsons Posts: 29Questions: 8Answers: 0

    I was able to accomplish this by using this guide:

    https://datatables.net/forums/discussion/34352/passing-datatable-object-to-initcomplete-callback

    I also found that it would not change the page unless I wrapped the page changing in a setTimeout. It appears to be functioning for me now however.

This discussion has been closed.