jqGrid TreeGrid问题

时间:2012-09-13 13:24:29

标签: javascript jqgrid

有人能解释一下我的错误吗?

我有以下代码:

function initTable() {


mydata = [{ "id": "1", "brandName": "7 Crown With Honey", "quality": "Standard", "minorRegionName": "North America", "year00": "", "year01": "", "level": "0", "parent": "", "isLeaf": "false", "expanded": "false" },
            { "id": "2", "brandName": "Amaretto di Florio", "quality": "Standard", "minorRegionName": "North West Europe", "year00": "", "year01": "", "level": "1", "parent": "1", "isLeaf": "true", "expanded": "false" },
            { "id": "3", "brandName": "Aniversario Rum", "quality": "Super Premium", "minorRegionName": "South America", "year00": "5", "year01": "6", "level": "1", "parent": "1", "isLeaf": "true", "expanded": "false" },
            { "id": "4", "brandName": "Archers", "quality": "Standard", "minorRegionName": "Asia", "year00": "2", "year01": "1", "level": "0", "parent": "", "isLeaf": "false", "expanded": "false" }
         ];

$("#list2").jqGrid({
    treeGrid: true,
    treeGridModel: 'adjacency',
    ExpandColumn: 'brandName',

            data: mydata,
            datatype: 'local',
            height: 300,

            colNames: ['brandName', 'minorRegionName','quality', 'year00', 'year01'],
            colModel: [{ name: 'brandName', index: 'brandName', width: 200 },
                                { name: 'minorRegionName', index: 'minorRegionName', width: 200 },
                                { name: 'quality', index: 'quality', width: 100},
                                { name: 'year00', index: 'year00', width: 80, align: "right", sorttype: "float", formatter: "number" },
                                 { name: 'year01', index: 'year01', width: 80, align: "right", sorttype: "float", formatter: "number"}],

        rowNum: 30,
        rowList:[10,20,30],
        pager: '#pager2',
        sortname: 'brandName',
        pgtext: "Page {0} of {1}",
        });


    $("#list2").jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false });
    //$("#list2").setGridParam({ datatype: 'local', page: 1, rowNum: 20 }).trigger('reloadGrid');
    }

很简单,不会产生具有嵌套行的TreeGrid。

我知道数据工作正常,因为如果我发表评论:

treeGrid: true,
    treeGridModel: 'adjacency',
    ExpandColumn: 'brandName',

果然显示数据。

我很确定这是显而易见的,但看不出它是什么。

1 个答案:

答案 0 :(得分:2)

主要问题是TreeGrid不支持datatype: "local"。因此,您必须手动添加关于addJSONData的数据(请参阅the answer)或使用datatype: "jsonstring"datastr: mydata和其他jsonReader(请参阅here })。

您的演示可以修改为例如the following demo