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

后端 未结 2 885
没有蜡笔的小新
没有蜡笔的小新 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:41

    I suppose that you load the data from the server using datatype: "json" in combination with loadonce: true option. The solution is very easy if you use free jqGrid fork of jqGrid. Free jqGrid allows to sort and to filter the data, returned from the server, before displaying the first page of data. One need to add forceClientSorting: true to force the applying the actions by jqGrid and postData.filters with the filter, which you need, and the option search: true to apply the filter:

    $("#grid").jqGrid({
        ...
        datatype: "json",
        postData: {
            // the filters property is the filter, which need be applied
            // to the data loaded from the server
            filters: JSON.stringify({
                groupOp: "AND",
                groups: [],
                rules: [{field: "hasData", op: "eq", data: "true"}]
            })
        },
        loadonce: true,
        forceClientSorting: true,
        search: true,
        // to be able to use "hasData" property in the filter one has to
        // include "hasData" column in colModel or in additionalProperties
        additionalProperties: ["hasData"],
        ...
    });
    

    See the demo https://jsfiddle.net/OlegKi/epcz4ptq/, which demonstrate it. The demo uses Echo service of JSFiddle to simulate server response.

提交回复
热议问题