在网格上完成本地数据类型后,过滤器无法正常工作

时间:2013-04-17 05:01:28

标签: jquery jqgrid mvcjqgrid

目前我在jqgrid面临一个问题。使用ajax调用加载网格后,我将数据类型更改为网格上的本地完成。之后,我试图过滤,但我得到零记录。任何帮助表示赞赏。

以下是我的代码: -

$("#orderformtable").jqGrid(
            {
                url : "getOrderFormProductList.htm?VENDORID=" + VENDORID
                        + "&LOCATIONID=" + LOCATIONID,
                mtype : 'GET',
                datatype : "json",
                colNames : [ 'Product', 'Pipeline Qty.', 'A', 'B', 'C',
                        'D', 'Order Qty.' ],
                colModel : [ {
                    name : 'PRODUCT_NAME',
                    index : 'PRODUCT_NAME',
                    width : 80,
                    editable : false,
                    hidden : false,
                    editrules : {
                        required : true
                    },
                    editoptions : {
                        disabled : true,
                        size : "40",
                        maxlength : "70"
                    }

                }, {
                    name : 'PIPELINE_QTY',
                    index : 'PIPELINE_QTY',
                    width : 20,
                    editable : false,
                    editoptions : {
                        size : "7",
                        maxlength : "6"
                    },
                    editrules : {
                        required : true
                    },
                    align : 'center'
                }, {
                    name : 'MAX_QTY',
                    index : 'MAX_QTY',
                    width : 15,
                    editable : true,
                    editoptions : {
                        size : "7",
                        maxlength : "6"
                    },
                    editrules : {
                        required : true
                    },
                    align : 'center'
                }, {
                    name : 'INSTOCK_QTY',
                    index : 'INSTOCK_QTY',
                    width : 20,
                    editable : false,
                    editoptions : {
                        size : "7",
                        maxlength : "6"
                    },
                    editrules : {
                        required : true
                    },
                    align : 'center'
                }, {
                    name : 'VENDOR_PIPELINE',
                    index : 'VENDOR_PIPELINE',
                    width : 20,
                    editable : false,
                    editoptions : {
                        size : "7",
                        maxlength : "6"
                    },
                    editrules : {
                        required : true
                    },
                    align : 'center'
                }, {
                    name : 'REQUIRED_QTY',
                    index : 'REQUIRED_QTY',
                    width : 20,
                    editable : false,
                    editoptions : {
                        size : "7",
                        maxlength : "6"
                    },
                    editrules : {
                        required : true
                    },
                    align : 'center'
                }, {
                    name : 'REORDER_QTY',
                    index : 'REORDER_QTY',
                    width : 20,
                    editable : true,
                    search : false,
                    editoptions : {
                        size : "7",
                        maxlength : "6"
                    },
                    editrules : {
                        required : true
                    },
                    align : 'center'
                } ],
                loadonce : true,
                localReader : {
                    repeatitems : true
                },
                hidegrid : false,
                postData : {},
                rowNum : 200,
                rowList : [ 200, 220, 230 ],
                height : 500,
                autowidth : true,
                rownumbers : true,
                pager : '#orderformpagination',
                sortname : 'PRODUCT_NAME',
                viewrecords : true,
                gridview : true,
                sortorder : "asc",
                caption : "",
                emptyrecords : "Empty records",
                loadonce : false,
                gridComplete : function() {
                    $("#orderformtable").setGridParam( {
                        datatype : 'local',
                        ignoreCase : true
                    });
                },
                loadComplete : function() {

                    var rowid = jQuery("#orderformtable").jqGrid(
                            'getDataIDs');
                    for ( var i = 0; i < rowid.length; i++) {

                        $('#orderformtable').jqGrid('editRow', rowid[i]);
                    }
                }
            });

下面是我的jsonarray重新构建的表单控制器: -

{
"total": 1,
"rows": [
    {
        "cell": [
            "Ball Pen",
            4,
            100,
            10,
            0,
            90
        ],
        "id": "1220"
    },
    {
        "cell": [
            "BATTERY DURACELL 9V PER PC",
            1,
            50,
            10,
            0,
            40
        ],
        "id": "1101"
    },
    {
        "cell": [
            "Brown Tape 2 inch per pc",
            0,
            30,
            10,
            0,
            20
        ],
        "id": "1108"
    },
    {
        "cell": [
            "CELLO TAPE 1 INCH- PER PC",
            0,
            80,
            10,
            0,
            70
        ],
        "id": "1115"
    },
    {
        "cell": [
            "CUTTER PAPER MEDIUM",
            0,
            25,
            10,
            0,
            15
        ],
        "id": "1122"
    },
    {
        "cell": [
            "Scissor big (per pc)",
            0,
            0,
            0,
            0,
            0
        ],
        "id": "1199"
    }
],
"records": 6,
"page": 1

}

1 个答案:

答案 0 :(得分:0)

我认为您遇到的主要问题是使用loadonce: trueloadonce: false。具有两次定义的相同属性的对象的定义将主要被解释为错误,但是如果Web浏览器确实将该属性的值解释为loadonce: false,则可以解决您描述的问题。

datatype'local'gridComplete的设置非常糟糕。可能你从一些非常古老的代码示例中获得了技巧。如果您使用loadonce: true,那么

  1. 来自服务器的数据将保存在本地,因此可以在本地搜索/过滤数据。
  2. 首次从服务器加载数据后 在本地保存数据。
  3. 如果您在datatype内设置"local"datatype,则将从本地保存从服务器加载的数据。因此,您无法使用本地数据过滤。

    此外,我建议您通过使用列模板来减少代码。例如,您可以使用'local'更改gridComplete项中任何属性的默认值(请参阅the answer)。您可以删除其他具有默认值的选项(cmTemplatecolModelpostData: {}localReader: { repeatitems: true }sortorder : "asc")。结果,您的代码可以重写为以下内容

    mtype : 'GET'