将 child 节点添加到显示为 Guriddo Treegrid 模型最后一行的第一个根节点
Adding a child node to the first root node showing as last row in Guriddo Treegrid model
我使用 Guriddo 库创建了 jqGrid TreeGrid(邻接模型)。
当我将新的 child 节点添加到第一个根节点时,它显示为 TreeGrid(在浏览器上)中的最后一条记录,而不是显示为 parent 下的 child 节点,因为该节点的 id 值更高比数据库中的其他记录。如何在parent节点展开时正确显示这些child节点。请参阅下图了解此问题。
数据库中的记录如下:
ID NAME DESCRIPTION PARENT_ID LEVEL IS_LEAF
==============================================================================
1 MGR Manager NULL 0 FALSE
2 DMGR Deputy 1 1 TRUE
3 HR HR NULL 0 FALSE
4 AHR HR 3 1 TRUE
5 SMGR Sales 1 1 TRUE
下面是网格设置代码:
$("#orgStrTable").jqGrid({
//"hoverrows":false,
//"viewrecords":false,
//"gridview":true,
url: u,
//"editurl" : saveUrl,
"ExpandColumn":"name",
//"sortname":"id",
sortable:false,
"scrollrows":true,
"treeGrid":true,
"treedatatype":"json",
"treeGridModel":"adjacency",
//"loadonce":true,
//"rowNum":1000,
"treeReader":{
"parent_id_field":"parentId",
"level_field":"level",
"leaf_field":"leaf",
"expanded_field":"expanded",
"loaded":"loaded",
"icon_field":"icon"
},
datatype: "json",
jsonReader : {
repeatitems : false
},
colNames:['ID', 'Name','Desc','Enabled','Parent'],
"colModel":[
{"name" :'id',"index":'id', "hidden":true, "key":true,sortable:false},
{"name":'name',"index":'name'},
{"name":'description',"index":'description',"search":false,sortable:false},
{"name":'active',"index":'active',"search":true,"editable":true,sortable:false},
{"name":'parentId',"index":'parentId',"hidden":true,sortable:false}
],
"pager": "#pagingDiv3",
multiselect:false
});
jQuery('#orgStrTable').jqGrid('navGrid','#pagingDiv3',
{
"edit":false,
"add":false,
"del":false,
"search":false,
"refresh":true,
"view":false,
"excel":false,
"pdf":false,
"csv":false,
"columns":false
},
{"drag":true,"resize":true,"closeOnEscape":true,"dataheight":150},
{"drag":true,"resize":true,"closeOnEscape":true,"dataheight":150}
);
数据库Table结构:
CREATE TABLE `org_str` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`description` varchar(500) DEFAULT '',
`active` bit(1) NOT NULL DEFAULT b'1',
`parent_id` bigint(20) DEFAULT NULL,
`level` int(11) NOT NULL,
`is_leaf` bit(1) NOT NULL DEFAULT b'1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
数据数组:
var dataArray = [
{"id":"1","name":"MGR","description":"Manager","active":"true","parentId":null,"level":0,"isLeaf":"false","loaded":"true","expanded":"true"},
{"id":"2","name":"DMGR","description":"Deputy","active":"true","parentId":"1","level":1,"isLeaf":"true","loaded":"true","expanded":"true"},
{"id":"3","name":"HR","description":"HR","active":"true","parentId":null,"level":0,"isLeaf":"false","loaded":"true","expanded":"true"},
{"id":"4","name":"AHR","description":"HR","active":"true","parentId":3,"level":1,"isLeaf":"true","loaded":"true","expanded":"true"},
{"id":"5","name":"SAL_MGR","description":"Sales Manager","active":"true","parentId":1,"level":1,"isLeaf":"true","loaded":"true","expanded":"true"},
];
您的示例运行良好,我认为您使用 addRowData 添加节点而不是 addChildNode 方法。见 docs here
您的代码演示是located here
添加节点 - select 第一行并添加所需的数据。你会看到记录被添加到合适的地方
更改以下网格选项后有效:
"sortname":"name",
"treeReader":{
"parent_id_field":"parentId",
"level_field":"level",
"leaf_field":"leaf",
"expanded_field":false,
"loaded":true,
"icon_field":"icon"
},
我使用 Guriddo 库创建了 jqGrid TreeGrid(邻接模型)。 当我将新的 child 节点添加到第一个根节点时,它显示为 TreeGrid(在浏览器上)中的最后一条记录,而不是显示为 parent 下的 child 节点,因为该节点的 id 值更高比数据库中的其他记录。如何在parent节点展开时正确显示这些child节点。请参阅下图了解此问题。
数据库中的记录如下:
ID NAME DESCRIPTION PARENT_ID LEVEL IS_LEAF
==============================================================================
1 MGR Manager NULL 0 FALSE
2 DMGR Deputy 1 1 TRUE
3 HR HR NULL 0 FALSE
4 AHR HR 3 1 TRUE
5 SMGR Sales 1 1 TRUE
下面是网格设置代码:
$("#orgStrTable").jqGrid({
//"hoverrows":false,
//"viewrecords":false,
//"gridview":true,
url: u,
//"editurl" : saveUrl,
"ExpandColumn":"name",
//"sortname":"id",
sortable:false,
"scrollrows":true,
"treeGrid":true,
"treedatatype":"json",
"treeGridModel":"adjacency",
//"loadonce":true,
//"rowNum":1000,
"treeReader":{
"parent_id_field":"parentId",
"level_field":"level",
"leaf_field":"leaf",
"expanded_field":"expanded",
"loaded":"loaded",
"icon_field":"icon"
},
datatype: "json",
jsonReader : {
repeatitems : false
},
colNames:['ID', 'Name','Desc','Enabled','Parent'],
"colModel":[
{"name" :'id',"index":'id', "hidden":true, "key":true,sortable:false},
{"name":'name',"index":'name'},
{"name":'description',"index":'description',"search":false,sortable:false},
{"name":'active',"index":'active',"search":true,"editable":true,sortable:false},
{"name":'parentId',"index":'parentId',"hidden":true,sortable:false}
],
"pager": "#pagingDiv3",
multiselect:false
});
jQuery('#orgStrTable').jqGrid('navGrid','#pagingDiv3',
{
"edit":false,
"add":false,
"del":false,
"search":false,
"refresh":true,
"view":false,
"excel":false,
"pdf":false,
"csv":false,
"columns":false
},
{"drag":true,"resize":true,"closeOnEscape":true,"dataheight":150},
{"drag":true,"resize":true,"closeOnEscape":true,"dataheight":150}
);
数据库Table结构:
CREATE TABLE `org_str` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`description` varchar(500) DEFAULT '',
`active` bit(1) NOT NULL DEFAULT b'1',
`parent_id` bigint(20) DEFAULT NULL,
`level` int(11) NOT NULL,
`is_leaf` bit(1) NOT NULL DEFAULT b'1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
数据数组:
var dataArray = [
{"id":"1","name":"MGR","description":"Manager","active":"true","parentId":null,"level":0,"isLeaf":"false","loaded":"true","expanded":"true"},
{"id":"2","name":"DMGR","description":"Deputy","active":"true","parentId":"1","level":1,"isLeaf":"true","loaded":"true","expanded":"true"},
{"id":"3","name":"HR","description":"HR","active":"true","parentId":null,"level":0,"isLeaf":"false","loaded":"true","expanded":"true"},
{"id":"4","name":"AHR","description":"HR","active":"true","parentId":3,"level":1,"isLeaf":"true","loaded":"true","expanded":"true"},
{"id":"5","name":"SAL_MGR","description":"Sales Manager","active":"true","parentId":1,"level":1,"isLeaf":"true","loaded":"true","expanded":"true"},
];
您的示例运行良好,我认为您使用 addRowData 添加节点而不是 addChildNode 方法。见 docs here
您的代码演示是located here
添加节点 - select 第一行并添加所需的数据。你会看到记录被添加到合适的地方
更改以下网格选项后有效:
"sortname":"name",
"treeReader":{
"parent_id_field":"parentId",
"level_field":"level",
"leaf_field":"leaf",
"expanded_field":false,
"loaded":true,
"icon_field":"icon"
},