8
我想让我的子网格与本地数据一起工作。然而,当我点击展开时,我只是得到一个装载框,就像网格试图从某处拉取数据。由于主网格的数据类型为datatype:'local'
,因此我假设我不需要subGridUrl
。还有什么我应该做的?jqGrid子网格与“本地”数据
我想让我的子网格与本地数据一起工作。然而,当我点击展开时,我只是得到一个装载框,就像网格试图从某处拉取数据。由于主网格的数据类型为datatype:'local'
,因此我假设我不需要subGridUrl
。还有什么我应该做的?jqGrid子网格与“本地”数据
没有直接的方法可以用本地数据定义子网格,但使用subGridRowExpanded
(Subgrid as Grid)可以相对容易地实现相同的行为。人们需要做的只是从网格的rowid中获取一些内部结构的子网格数据。例如,如果你将有局部栅格地图作为
var myGridData = [
// main grid data
{id: "m1", col1: "11", col2: "12"},
{id: "m2", col1: "21", col2: "22"}
],
mySubgrids = {
m1: [
// data for subgrid for the id=m1
{id: "s1a", c1: "aa", c2: "ab", c3: "ac"},
{id: "s1b", c1: "ba", c2: "bb", c3: "bc"},
{id: "s1c", c1: "ca", c2: "cb", c3: "cc"}
],
m2: [
// data for subgrid for the id=m2
{id: "s2a", c1: "xx", c2: "xy", c3: "xz"}
]
};
里面的subGridRowExpanded
你可以用下面的代码创建子网格:
$("#grid").jqGrid({
datatype: 'local',
data: myGridData,
colNames: ['Column 1', 'Column 2'],
colModel: [
{ name: 'col1', width: 200 },
{ name: 'col2', width: 200 }
],
...
subGrid: true,
subGridRowExpanded: function (subgridDivId, rowId) {
var subgridTableId = subgridDivId + "_t";
$("#" + subgridDivId).html("<table id='" + subgridTableId + "'></table>");
$("#" + subgridTableId).jqGrid({
datatype: 'local',
data: mySubgrids[rowId],
colNames: ['Col 1', 'Col 2', 'Col 3'],
colModel: [
{ name: 'c1', width: 100 },
{ name: 'c2', width: 100 },
{ name: 'c3', width: 100 }
],
...
});
}
});
The demo显示结果住:
大回答奥列格。我将在我的代码中实现这个功能!我实际上使用这个结合从网格到网格的拖放(从我的其他[问题](http://stackoverflow.com/questions/10146892/jqgrid-drag-and-drop-row-check)) 。 – FastTrack 2012-04-16 20:24:42
@FastTrack:不客气! – Oleg 2012-04-16 20:25:59
@oleg很好的回答,它帮助我解决了一个重大问题,尽管我只能对它进行一次提升。 :( – 2012-06-07 07:24:28