jqGrid treeGrid展开折叠不起作用

时间:2012-03-12 23:55:02

标签: jquery json jqgrid treegrid

我正在尝试使用jqGrid 4.2.1设置一个treeGrid,在一些工作后,它看起来没问题,但扩展折叠不起作用。只有图标切换,但组保持可见。

设置如下

    $("#list").jqGrid({
                treeGrid: true,
                treeGridModel: 'adjacency',
                ExpandColumn: 'BreakdownTag',
                ExpandColClick: true,
                url: '/AsyncData/Breakdown.ashx',
                datatype: 'json',
                mtype: 'GET',
                colNames: ['Superior Tag', 'Breakdown Tag', 'Tag Description'],
                colModel: [
                    { name: 'SuperiorTag', id: 'SuperiorTag', index: 0, width: 250, 
hidden: true, align: 'left', sortable: false, classes: 'indeling', title: false },
                    { name: 'BreakdownTag', id: 'BreakdownTag', index: 1, width: 250,
 align: 'left', sortable: false, classes: 'indeling', title: false, visible: false },
                    { name: 'TagDescription', id: 'TagDescription', index: 2, width: 250,
 align: 'left', sortable: false, classes: 'indeling', title: false },],
                rowNum: 20000,
                viewrecords: true,
                loadui: "disable",
                emptyrecords: "Geen data gevonden...",
                height: "100%",
                treeIcons: { leaf: 'ui-icon-document-b' },
                loadonce: true,
                hoverrows: false
 }

            });

json对象是:

    {
    "total": 1,
    "page": 1,
    "records": 3,
    "rows": [
        {
            "i": 1,
            "cell": [
                "",
                "First",
                "Description for First",
                0,
                "null",
                false,
                true,
                true
            ]
        },
        {
            "i": 2,
            "cell": [
                "First",
                "Second",
                "Description for Second",
                1,
                "First",
                false,
                true,
                true
            ]
        },
        {
            "i": 3,
            "cell": [
                "Second",
                "Third",
                "Description for Third",
                2,
                "Second",
                false,
                true,
                true
            ]
        }
    ]
}

正如所说的那样,直到点击一个节点才能折叠它(evreything显示expanddend),图标会切换,但行保持可见。 我现在有点无能为力......

1 个答案:

答案 0 :(得分:1)

JSON数据中有两个错误,JavaScript代码中有一个小错误。

在JSON dada中,您应使用id代替i作为项ID。要指定父元素,您应该使用id而不是'BreakdownTag'列中的值(在下面的示例中使用2而不是“Second”):

{
    "i": 3,
    "cell": [
        "Second",
        "Third",
        "Description for Third",
        2,
        "Second",
        false,
        true,
        true
    ]
}

应固定为

{
    "id": 3,
    "cell": [
        "Second",
        "Third",
        "Description for Third",
        2,
        2,
        false,
        true,
        true
    ]
}

其他次要JavaScript错误是在colModel末尾使用尾随逗号。组合},]应替换为}]

更改后,

The demo工作正常。