jqGrid:如何仅加载属性设置为true的行 [英] jqGrid: How to load only rows that an attribute is set to true

查看:61
本文介绍了jqGrid:如何仅加载属性设置为true的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON对象,如下所示:

I have a JSON Object as the following:

{
  "rows": [
  {
    "id":1,
    "name": "Peter",
    "hasData": true,
  },
  {
    "id":2,
    "name": "Tom",
    "hasData": false,
  }]
}

而且我希望jqGrid仅加载有数据的行,即"hasData" == true时.

And I want the jqGrid to load only rows that have data, meaning when "hasData" == true.

首先,我想知道这样做的最佳方法是什么,其次,我想知道如何做到这一点.

I am firstly wondering what is the best way to do such and secondly wondering how to do it.

更新: 我尝试了以下方法:

UPDATE: I have tried the following:

gridComplete: function(){
  var rowObjects = this.p.data;
    for(var i = 0; i<rowObjects.length;i++){
      if(rowObjects[i].hasData == false){
        $(this).jqGrid('delRowData',rowObjects[i].id);
      }
    }
  },

但是问题是当我转到下一页时,所有数据都是从JSON加载的.

but the problem is when I go to the next page, all the data is loaded new from the JSON.

推荐答案

我可以向您推荐其他解决方案(以防您使用 Guriddo jqGrid ),可以与任何数据类型和任何设置一起使用.这个想法是使用beforeProcessing事件来过滤所需的数据.

I can recommend you another solution (in case you use Guriddo jqGrid) , which can be used with any datatype and any settings. The idea is to use beforeProcessing event to filter the needed data.

为此,我们假设数据与您描述的相同.这是代码:

For this purpose we assume that the data is like described from you. Here is the code:

$("#grid").jqGrid({
...
        beforeProcessing : function (data, st, xhr) {

            var test= data.rows.filter(function (row) {
                if(row.hasData == true ) { // true is not needed but for demo
                    return true;
                } else {
                    return false;
                }
            });
            data.rows = test;
            return true;
        }
...
});

我想该脚本可以在免费的jqGrid中运行,以防您使用它们

I suppose the script will work in free jqGrid in case you use them

这篇关于jqGrid:如何仅加载属性设置为true的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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