refresh table every 1 second
refresh table every 1 second
itsbucket
Posts: 2Questions: 1Answers: 0
I'm trying to refresh a data table I have every 2 seconds.
my code :
<script type="text/javascript">
var user = '<?php echo $_SESSION['username']?>';
jQuery('.js-dataTable-full-pagination-help').DataTable({
pagingType: "full_numbers",
columnDefs: [ { orderable: false, targets: [ 4 ] } ],
pageLength: 10,
lengthMenu: [[5, 10, 15, 20], [5, 10, 15, 20]],
dom: 'lfBrtip',
buttons: [
'copy',
{
extend: 'excel',
messageTop: 'report'
},
{
extend: 'pdf',
title: ' report.'
},
{
extend: 'print',
messageTop: 'printed by - '+user,
title : ' report',
exportOptions: {
columns: [1, 2,3,4, 5 ]
}
}
]
});
</script>
what i tried :
setInterval(refreshTable , 1000 );});
and I tried ajax.reload...
I get this error :
Uncaught SyntaxError: Unexpected identifier
I have an ajax code to add values to the DB and showing them in the data table .. I want to refresh the table every 2 seconds so when the user adds something it appears on the table immediately.
EDIT: Updated post to use Markdown formatting
This discussion has been closed.
Answers
This is simply a syntax error in your JS code. Not sure about the
setInterval
code but you do have an error in this line:Guessing
username
is a variable the line should look like this:If you are still having a problem maybe you can post a test case with your code.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
@kthorngren Please check
Live data
I added a $ to this line:
var datatables = $('.js-dataTable-full-pagination-std').DataTable({
Now I get this error:
In the test case you didn't init the Datatable with
ajax
which I believe is the cause of the above error when theapi ajax.reload()
is executed.The updated example is here:
http://live.datatables.net/gowogeke/2/edit
Kevin