【问题标题】:jqGrid loading aspx webservice using mtype post json not loading gridjqGrid使用mtype post json加载aspx webservice不加载网格
【发布时间】:2011-11-04 18:04:29
【问题描述】:

我已经为此苦苦挣扎了好几天了。

奇怪的是,我已经通过各种试验让它工作了 - 但现在它根本没有加载

这是我的设置:

$("#table-Select").jqGrid({
                        url: 'SelectionListService.asmx/GetList',
                        mtype: 'POST',
                        datatype: 'json',
                        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, 
                        postData: { SelectionType:  'Project' },
                        colNames: ['id', 'Title', 'DocumentID'],
                        colModel: [
                                    { name: 'id', index: 'id', width: 20,hidden: false },
                                    { name: 'Title', index: 'Title' ,width: 220,hidden:false},
                                    { name: 'DocumentID', index: 'DocumentID',width: 220, hidden: false}
                                    ],
                        hidegird: false,
                        autowidth: true,
                        //height: 'auto',
                        rowNum: 0,
                        rowList: [10, 20, 30],
                        pager: jQuery('#table-SelectPager'),
                        sortname: 'Title',
                        viewrecords: true,
                        loadonce: true,
                        sortorder: "desc",
                        caption: "Select Project",
                        //fixes Invalid JSON Primitive error
                        serializeGridData: function (postData) { 
                                if (postData.searchField === undefined) postData.searchField = null; 
                                if (postData.searchString === undefined) postData.searchString = null; 
                                if (postData.searchOper === undefined) postData.searchOper = null; 
                                //if (postData.filters === undefined) postData.filters = null; 
                                return JSON.stringify(postData);
                            }, 
                         jsonReader: {
                            root: "rows",
                            page: "page",
                            total: "total",
                            records: "records"
                            }

                        }).navGrid('#table-SelectPager', { edit: false, add: false, del: false });

这是来自 WebService 调用的 JSON 数据:

{"d":{"__type":"NCR.SelectionListService+JQGrid","page":1,"total":4,"records":4,"rows":[{"id":"1","DocumentID":"pgmprj://aecomme/newdohaportproject/envcomp","Title":"NDPP-Environmental Compliance Monitoring"},{"id":"2","DocumentID":"pgmprj://aecomme/newdohaportproject/ndpp-portbasinandinnerbreakwatersconstruction","Title":"NDPP-Port Basin and Inner Breakwaters Construction"},{"id":"3","DocumentID":"pgmprj://aecomme/newdohaportproject/ndpp-programmanagement","Title":"NDPP-Program Management"},{"id":"4","DocumentID":"pgmprj://aecomme/newdohaportproject/ndpp-supplementarysiteinvestigation","Title":"NDPP-Supplementary Site Investigation"}]}}

我知道它一定是我缺少的一些简单的东西 - 但在我看过所有示例之后 - 我不知道我缺少什么。

任何想法将不胜感激。

【问题讨论】:

    标签: asp.net json web-services jqgrid


    【解决方案1】:

    您应该将jsonReader 选项修改为以下内容:

    jsonReader: {
        root: "d.rows",
        page: "d.page",
        total: "d.total",
        records: "d.records",
        repeatitems: false
    }
    

    the demo

    【讨论】:

    • 感谢奥列格 - 我正要击中那个,你也打败了我 - 再次感谢。奇怪的是,当我单击排序功能时-我的所有行都消失了-即使根据 $("#table-Select").jqGrid('getGridParam', "records");
    • UPDATE,发现排序问题,出于某种原因,我在某人的示例中看到了 rowNum: 0 ,所以我尝试在我的上设置这个,它加载第一组查找,但这样做会导致排序清除网格上的记录。喜欢 jqGrid - 感谢 Oleg!
    • @Nutshell:我刚刚发现了同样的问题。您还应该在id 列中包含sorttype: 'int'。请参阅修改后的演示。如果问题解决了可以"accept"回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 2014-11-07
    相关资源
    最近更新 更多