jqGrid Search引发错误:TypeError:无法读取未定义的属性“searchrules”

时间:2012-02-16 14:40:09

标签: jquery asp.net-mvc-3 jqgrid

当我切换jqGrid以使用高级搜索时 - 它似乎工作正常,除了它弹出上面的错误“TypeError:无法读取Chrome中的属性'搜索规则'在Chrome中,当你点击查找按钮时。奇怪的是在Firefox中,错误是:“TypeError:g未定义”。

如果我只是单击确定错误,页面回发到我的MVC控制器就好了。我只想要错误 - 任何想法? 这是网格代码:

jQuery("#list").jqGrid({
            url: '/Audit/GridData/',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Id', 'Date', 'Username', 'ObjectName', 'Event', 'Module'],
            colModel: [
      { name: 'Id', index: 'Id', width: 100, align: 'left', searchrules: { required: true }, search: true },
      { name: 'Date', index: 'DateStamp', width: 100, align: 'left', searchrules: { required: true }, search: true },
      { name: 'Username', index: 'Username', width: 200, align: 'left', searchrules: { required: true }, search: true },
      { name: 'ObjectName', index: 'ObjectType', width: 200, align: 'left', searchrules: { required: true }, search: true },
      { name: 'Event', index: 'Event', width: 120, align: 'left', searchrules: { required: true }, search: true },
      { name: 'Module', index: 'Module', width: 120, align: 'left', searchrules: { required: true }, search: true}],
            pager: '#pager',
            rowNum: 10,
            postData: {
                filters: '{"groupOp":"AND","rules":[{"field":"invdate","op":"gt","data":"2007-09-06"},{"field":"invdate","op":"lt","data":"2007-10-04"},{"field":"name","op":"bw","data":"test"}]}'
            },
            pgbuttons: true,
            rowList: [5, 10, 20, 50],
            sortname: 'Id',
            sortorder: "desc",
            viewrecords: true,
            imgpath: 'http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/redmond/images/',
            caption: 'Audits'
        }).navGrid('#pager', { search: true, edit: false, add: false, del: false, searchtext: "Search" }, {}, {}, {}, { multipleSearch: true, sopt: ['eq', 'bw', 'cn', 'gt', 'lt'] });

由于

1 个答案:

答案 0 :(得分:1)

您使用postData.filters的非常奇怪的值。它包含网格中不存在的invdatename字段的规则。我认为正确的数据将类似于

postData: {
    filters: '{"groupOp":"AND","rules":[' +
        '{"field":"DateStamp","op":"gt","data":"2007-09-06"},' +
        '{"field":"DateStamp","op":"lt","data":"2007-10-04"},' +
        '{"field":"Username","op":"bw","data":"test"}]}'
}

您应该使用您使用的index的{​​{1}}属性中的值。

此外,您应该删除deprecated选项colModel,该版本将被版本高于3.4.x的jqGrid忽略。