自动刷新DataTables表,并重新加载整个页面 [英] Auto refresh DataTables table with reloading the whole page

查看:1313
本文介绍了自动刷新DataTables表,并重新加载整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以指导如何每隔1分钟刷新一次数据表数据而无需重新加载整个页面.

Is anyone able to guide on how to refresh datatables datas in every 1min interval without reloading the entire page.

这是我的代码:

$(document).ready( function () {
           var refreshTable = $('#id_css').DataTable({
                "sAjaxSource": 'ajax/alert_data.txt',
                "bServerSide": true,
                "iDisplayLength": 100,
                "bFilter": false,
                "aaSorting" : [[2, "desc"]],
                "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                    if ( aData[2] == "5" )
                    {
                        $('td', nRow).css('background-color', 'Red');
                    }
                    else if ( aData[2] == "4" )
                    {
                        $('td', nRow).css('background-color', 'Orange');
                    }
                 }

              });
setInterval (function test() {
refreshTable.fnDraw();
}, 1000);
 });

我已尝试使用此插件 fnReloadAjax.js ,但一直收到 TypeError:refreshTable.fnReloadAjax不是函数.这是我的用法:

I have tried using this plugin fnReloadAjax.js but keep getting TypeError: refreshTable.fnReloadAjax is not a function. This is how I used it:

setInterval (function test() {
refreshTable.fnReloadAjax();
}, 1000);

并且我还添加了其CDN

and i have also added its cdn

<script src="//cdn.datatables.net/plug-ins/725b2a2115b/api/fnReloadAjax.js"></script>

任何帮助或指导将不胜感激.

Any assistance or guide will be much appreciated.

推荐答案

奇怪的是,将 DataTable 更改为 dataTable 是导致此操作始终失败的根本原因.那是小d而不是大写D,真烦人...

Its strange that changing the DataTable to dataTable was the root cause of this failing the whole time. That is small d instead of capital D, really annoying...

$(document).ready( function () {
       var refreshTable = $('#id_css').dataTable({
            "sAjaxSource": 'ajax/alert_data.txt',

这篇关于自动刷新DataTables表,并重新加载整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆