【问题标题】:jqGrid: JSON Returned by Web Service Won't Bind to SubgridjqGrid:Web 服务返回的 JSON 不会绑定到子网格
【发布时间】:2019-04-02 15:37:47
【问题描述】:

我正在尝试将子网格添加到现有的 jqGrid。

当我展开父行时,会调用 URL,并且 JSON 响应看起来不错(在我看来),但它没有绑定到子网格行。

如果我通过在浏览器中粘贴 URL 直接调用 Web 服务,响应看起来不错。

这是完整的 jqGrid 定义:

            /* +++ Group Grid Definition +++ */
            $("#<%= id %>_groupTable").jqGrid({
                loadonce: true,
                datatype: 'local',
                //sortable: true,
                gridview: true,
                editurl: "clientArray",
                autowidth: true,
                rowNum: 12000,
                height: 150,
                multiselect: false,
                hidegrid: false,
                pgbuttons: false,
                pginput: false,
                sortname: "Date",
                sortorder: "desc",
                jsonReader: {
                    root: "inbox",
                    page: "page",
                    total: "total",
                    records: "records",
                    id: "id",
                    repeatitems: false,
                    subgrid: { repeatitems: true }
                },
                toolbar: [true, "bottom"],
                colModel: [
                {
                    name: 'userGroupId',
                    label: '{{VIEW_LABEL}}',
                    index: 'userGroupId',
                    width: 50,
                    fixed: true,
                    hidden: true,
                    //sortable: false,
                    align: 'center'
                }, {
                    name: 'desc',
                    label: '{{NAME_LABEL}}',
                    index: 'desc',
                    width: 130,
                    align: 'center',
                    sorttype: 'text'
                }],
                hidegrid: false,
                gridComplete: function () {
                    $('#<%= id %> .loading').remove();
                    $('#<%= id %>_groupTable').jqGrid('setSelection', 1);
                },
                loadComplete: styleGroupRows,
                afterInsertRow: styleGroupRows,
                subGrid: true,
                subgridtype: 'json',
                subGridUrl: '/ws/users/groupusers',
                subGridModel: [
                    {
                        name: ['Name'],
                        width: [200],
                        params: ['userGroupId']
                    }]
            }).jqGrid('bindKeys', {
                'scrollingRows': true
            });

这是来自网络服务的 JSON 响应:

{'rows':['User 1312','User 1316','User 1286','User 1149']}

我希望子网格中只有一列用户名,但只显示列标题。

【问题讨论】:

    标签: json jqgrid subgrid


    【解决方案1】:

    您的 subGrid 响应不符合规则。

    尝试以下响应:

    {"rows":[{"id":"1","cell":["User 1312"]},{"id":"2","cell":["User 1316"]}]}
    

    【讨论】:

    • 感谢托尼,但仍然不高兴。我还进行了以下更改,但仍然没有数据。子网格:{重复项:真,根:“行”,单元格:“单元格”}
    • 会不会是它从父网格继承的东西搞砸了?
    • 检查您的回复是否与我的回答中描述的一致。在我们的旧网站上有一个工作演示。转到 here ,然后在左侧选择 New since beta 3.0 然后 -> Subgrid with JSON
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-14
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多