【问题标题】:support unknown number of levels of hierarchy in jqGrid在 jqGrid 中支持未知数量的层次结构
【发布时间】:2011-12-18 14:12:42
【问题描述】:

我正在使用 jqGrid,我需要显示一个未知层数(子网格)的树形网格。

在 jqGrid 演示中有一个分层网格的示例,但前提是您提前知道级别数,在这种情况下它只支持 2 个级别。

这里是代码:jqGrid subgrid example

知道如何支持未知数量的树节点吗?即,有时可能是 2 级,有时可能是 1(仅根)级别,有时可能是 4 级等等......

谢谢

【问题讨论】:

    标签: javascript jquery jqgrid tree


    【解决方案1】:

    我正在这样做。

    $("#TopLevelGrid").jqGrid({
        ...        
        subGrid: true,
        subGridRowExpanded: expandScript,
        ...
    });
    // Append information about the level to the TopLevelGrid html-table element
    $("#TopLevelGrid").data("currentLevelId", 1);
    $("#TopLevelGrid").addClass("MyGrid");      // Ensure that html-table has class MyGrid
    
    function expandScript(parentDivId, parentRowId)
    {
            ...
            var parentTable = $("#" + parentDivId").closest("table.MyGrid");
            var parentLevelId = $(parentTable).data("currentLevelId");
    
            var currentLevelId = parentLevelId + 1;                     // calculate the ID of the current level
            var currentLevelHasChildLevel = true;                       // calculate if the current level has a childLevel
            // Append a table-element which will hold the new grid;     // the same as the jqGrid-subgrid example
            $('#' + parentDivId).append('<table class=\"MyGrid\" id=\"ChildGrid_' + currentLevelId + '\"></table><div id=\"Pager_ChildGrid_' + currentLevelId + '\"></div><br />');
            $('#ChildGrid_' + currentLevelId ').jqGrid({
                ...
                subGrid: currentLevelHasChildLevel,
                subGridRowExpanded: expandScript,                       // recursive call to expandScript function
                ...
            });
            // Save the currentLevelId as custom-data element bound to the html-table element which will also hold the child-grid
            $("#ChildGrid_" + currentLevelId).data("currentlevelid", currentLevelId);
            ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-16
      • 2020-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-29
      相关资源
      最近更新 更多