JQGrid / JSGrid。在创建网格后添加其他行(数据库中的大量记录)

时间:2018-03-07 09:26:27

标签: javascript json ajax jqgrid jsgrid

我有一个返回大量数据(json)的查询。这需要很长时间才能将网格呈现给用户。所以我想要做的是使用过滤器(比如当前年份的记录)触发初始查询并让网格构建。

网格呈现给用户,他可以开始工作。

同时我发出第二个查询(在后台)以获取所有其他记录(除当前年份之外的所有记录)。

现在我想将这些记录添加到现有网格中。没有用户注意到。

这可能吗?

我认为JSgrid和JQgrid的行为相同,但我使用的是JSGrid

谢谢,迈克

2 个答案:

答案 0 :(得分:0)

只需在您的功能上设置延迟计时器。我不确定用户是否会注意到这些变化。但我认为这是一个很好的起点。

以下是如何使用setTimeout()的示例;

这将允许您的功能在一段时间后执行。因此,当用户加载表并开始工作时。您将触发重新填充表格的其他功能(在一定时间之后)。我不确定你的表是如何填充的,所以不确定执行是否对用户不可见。

var delayInMilliseconds = 1000; //1 second

   setTimeout(function() {
      //your code to be executed after 1 second
    }, delayInMilliseconds);` 

答案 1 :(得分:0)

在Guriddo jqGrid的情况下,您可以先加载一小部分数据,然后使用grid complete事件将数据类型设置为local,将所有数据加载到data参数中并刷新索引。加载的变量用于防止在排序打包等情况下重复加载 - 即代码只执行一次

代码and demo

    var loaded = false;
    $(document).ready(function () {
        $("#jqGrid").jqGrid({
            // url to load initially 10 records
            url: 'grid.php',
            datatype: "json",
....

            gridComplete : function() {
                // if the all the data is not loaded 
                if(!loaded)  {
                    // set the datatype to local
                    this.p.datatype='local';
                    var ts = this;
                    $.ajax({
                        "url": "grid.php",
                        "dataType" : "json",
                        // instruct the server to get all the data with the same sortining
                        "data" : { oper: 'grid', page:1, totalrows : -1, sidx : 'CustomerID', sord : 'asc' },
                        success :function( resp ) {
                            // when loaded  simple attach the response data to data array
                            ts.p.data = resp.rows;
                            // refresh the indexes
                            ts.refreshIndex();
                            // mark that the data is loaded in order no to do it again
                            loaded = true;
                        }
                    });
                }

            }
        });