jqGrid: How to load only rows that an attribute is set to true

后端 未结 2 884
没有蜡笔的小新
没有蜡笔的小新 2020-12-21 19:49

I have a JSON Object as the following:

{
  \"rows\": [
  {
    \"id\":1,
    \"name\": \"Peter\",
    \"hasData\": true,
  },
  {
    \"id\":2,
    \"name\":         


        
2条回答
  •  执笔经年
    2020-12-21 20:42

    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;
            }
    ...
    });
    

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

提交回复
热议问题