简体   繁体   English

jQuery jTable由Ajax闪烁

[英]jQuery jTable is blinking by ajax

When I bind data to jquery-jTable by using ajax, the table is blinking by timer's period. 当我使用ajax将数据绑定到jquery-jTable时,该表按计时器的周期闪烁。

I used jquery.timer.js and jquery.jtable.js 我使用了jquery.timer.js和jquery.jtable.js

Here is my javascript code. 这是我的JavaScript代码。


function dispAlarmTable(){
    var d = new Date();
    $("#alarmTableContainer").jtable({
        ajaxSettings: {
            type: 'POST',
            dataType: 'json'
        },
        actions:{
            listAction: 'http://localhost/alarm.php?t=' + d.getTime()
        },
        fields:{
            vmax:{title:'vmax'},
            imax:{title:'imax'},
            time:{title:'time'}
        }
    });
    $("#alarmTableContainer").jtable('load');
}
var timer = $.timer(function(){ dispAlarmTable(); }, 1000, true);

How can I avoid the blinking (white page and table, white page and table... by 1 second)? 如何避免闪烁(白页和表格,白页和表格... 1秒钟)?

You're recreating the table every second. 您每秒都在重新创建表。

This involves clearing the previous contents of the element, re-initializing the basic structure, then waiting for the server to rely before re-populating it. 这涉及清除元素的先前内容,重新初始化基本结构,然后等待服务器依赖,然后重新填充它。

This also resets any user changes such as sorting. 这也将重置任何用户更改,例如排序。

Instead, you should update the data within the existing table instance. 相反,您应该更新现有表实例中的数据。
The reload function does this. 重新加载功能可以做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM