Cycling through display of table entries on a timer?

Cycling through display of table entries on a timer?

OcenOcen Posts: 3Questions: 2Answers: 0

I need to display 10 entries from the table, wait 10 seconds, then fade out (or slide out) those and display (by fade-in or slide-in) the next 10. Once all entries have been displayed, the program should loop back around to the first 10. I am pretty new to using DataTables and have no clue how to go about this. Could someone please help me? thanks!

This question has an accepted answers - jump to answer

Answers

  • sliekenssliekens Posts: 97Questions: 17Answers: 2
    edited November 2016 Answer ✓

    Use the API
    https://datatables.net/reference/api/

    In particular, use page(), page(set) and page.len() to loop through pages in the table.
    https://datatables.net/reference/api/page()

    Use setInterval() to put the whole thing on a timer.

    var table = $('#table').DataTable();
    setInterval(function() {
        if (table.page() + 1 === table.page.len()) {
            table.page('first');
        } else {
            table.page('next');
        }
        table.draw('page');
    }, 10000)
    

    Don't forget to call draw() at the end or you won't see the changes.

    As for animating it (fading/sliding), I don't know if you can do that.

  • OcenOcen Posts: 3Questions: 2Answers: 0

    Thank you! This worked perfectly.

This discussion has been closed.