reload json from datatable and show timer in html
reload json from datatable and show timer in html
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
This discussion has been closed.
Answers
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
like reload function in json data...
Sorry, I'm still unclear what the problem is. Is
ajax.reload()
not working for you?Kevin
work for me. just me need show time in html...
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.
Looks like
$('#timer').html(reloadData)
should display10
in your HTML element with the id oftimer
. Is this not working?Kevin
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.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