reload json from datatable and show timer in html

reload json from datatable and show timer in html

ycusoyycusoy Posts: 27Questions: 5Answers: 0

hello, i'm write like this but timer not load in html.

    <script>
        $(document).ready(function() {
            $('#example').DataTable({
                ....
            });

            var reloadData = 10;
            setInterval(function() {
                ajax.reload();
            }, reloadData * 1000)

            $('#timer').html(reloadData)

            function updateTimer() {
                a = parseInt($('#timer').html())
                $('#timer').html(a - 1)
                if (a > 0)
                    timer = setTimeout(updateTimer, 1000);
            }

            updateTimer(timer)
        })
    </script>
    <span id="timer"></span>
    <table id="example">
        ...
    </table>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    Answer ✓

    Not sure I understand the question. Can you provide a test case showing the problem?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    You can use one of the ajax templates here as a base for the test case and to use the ajax.reload() API.
    https://datatables.net/manual/tech-notes/9#Ajax

    Kevin

  • ycusoyycusoy Posts: 27Questions: 5Answers: 0

    like reload function in json data...

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Sorry, I'm still unclear what the problem is. Is ajax.reload() not working for you?

    Kevin

  • ycusoyycusoy Posts: 27Questions: 5Answers: 0

    work for me. just me need show time in html...

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Thats more a generic web development question, not a Datatables issue. If you would like help please provide a test case so we can work with your code to see what it is doing. SO is the place for general Javascript, jQuery and HTML questions.

    just me need show time in html

    Looks like $('#timer').html(reloadData) should display 10 in your HTML element with the id of timer. Is this not working?

    Kevin

  • ycusoyycusoy Posts: 27Questions: 5Answers: 0
    edited June 2019

    I think maybe the timer function is included in the datatable based on data that appears in realtime. so .. it work, but stops at number -1 in the html and stays there. while I see no changes to the data received recently.

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    I think we will need to see a test case so we can help. Above I gave links to help get you started. You can use this as a base Datatables with ajax data:
    http://live.datatables.net/ajax-objects/1/edit

    Please update the example replicating your issue.

    Kevin

This discussion has been closed.