我正在使用 jqGrid,我需要显示一个具有未知数量级别(子网格)的树形网格。
jqGrid 演示中有一个分层网格的示例,但只有当您提前知道级别数时才有效,在本例中它仅支持 2 级。
知道如何支持未知数量的树节点吗?即,有时可能是 2 个级别,有时是 1 个(仅根)级别,有时是 4 个级别,依此类推...
谢谢
最佳答案
我正在做这个。
$("#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);
...
}
关于javascript - 支持 jqGrid 中未知数量的层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8552284/