1
我正在使用jqGrid,我需要顯示具有未知級別(子網格)數量的樹形網格。在jqGrid中支持未知數量的層次結構級別
在jqGrid演示中有一個分層網格的例子,但只有在事先知道層數的情況下才是好的,在這種情況下它只支持2個層次。
下面是代碼:jqGrid subgrid example
任何想法如何支持數目不詳的提前樹節點?即,有時它可能是2層,有時1(只有root)的水平,有時4個級別等等...
謝謝
我正在使用jqGrid,我需要顯示具有未知級別(子網格)數量的樹形網格。在jqGrid中支持未知數量的層次結構級別
在jqGrid演示中有一個分層網格的例子,但只有在事先知道層數的情況下才是好的,在這種情況下它只支持2個層次。
下面是代碼:jqGrid subgrid example
任何想法如何支持數目不詳的提前樹節點?即,有時它可能是2層,有時1(只有root)的水平,有時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);
...
}