jqGrid (v4.1.2) treegrid addChildNodes 未正确将条目添加到网格中
我目前正在努力建立一个树形网格,我将重写数据函数来调用 Thrift 服务来填充数据。我的想法是,我只加载父节点,然后当节点展开时,它将动态调用 thrift 服务来填充数据。当我尝试动态加载子项时,树形网格的行为方式遇到了一些怪癖。它将很好地加载初始列表,但是当我动态加载子级时,它不会在父级展开时添加它。现在,如果您展开第二个条目,它会将子项添加到列表中的正确位置,但它不会将其视为 287 的子项。
我似乎无法理解我做错了什么,因为它没有小时候不想正确添加。
// The data that is returned via thrift to fill in the initial entry in the table
{
"total" : "13″,
"page":"1″,
"records": "720″,
"rows" : [
{"id" : "287","cell" : ["287","MDXX00025",true,0,null,false,false] }
,{"id" : "544″,"isLeaf":true,"cell" : ["544","MDXX00460",true,0,null,false,false] }]
}
// How jqGrid is configured with a oData object that contains the child I want to fill in.
var oData = { "rows" : [
{"id" : "7220","parent":287,"level":"1","isLeaf":true,"loaded":true,"empty":"MDXX00450" }]
};
function DoWork(postdata)
{
var sData = client.NavigateTable(postdata._search,postdata.page,postdata.rows,postdata.sidx,
postdata.sord,postdata.totalrows);
var obj = jQuery.parseJSON(sData);
var thegrid = jQuery("#addtree")[0];
thegrid.addJSONData(obj);
}
function DoTreeWork(postdata)
{
var thegrid = $("#addtree");
thegrid.jqGrid ('addChildNode', oData.rows[0].id, oData.rows[0].parent, oData.rows[0]);
}
jQuery(document).ready(function(){
$.jgrid.defaults = $.extend($.jgrid.defaults,{loadui:"enable"});
jQuery("#addtree").jqGrid({
datatype: function(postdata)
{
DoWork(postdata);
},
treedatatype: function (postdata)
{
DoTreeWork(postdata);
},
treeGrid: true,
treeGridModel: 'adjacency',
colNames:["id","empty","docno,"],
colModel:[
{name:'id',index:'id', width:20,key:true, editable:false},
{name:'empty',index:'empty',width:10},
{name:'docno',index:'docno', width:30, editable:true}
],
pager : "#paddtree",
treeGrid: true,
ExpandColumn : 'name',
editurl:'server.asp',
viewrecords: true,
autowidth: true,
height:'400',
rowNum:52,
rowTotal:100,
gridview: true,
sortorder: "asc",
sortname: 'id',
caption: "Grid"
});
jQuery("#addtree").jqGrid('navGrid',"#paddtree",{edit:true,add:false,del:true,search:false});
});
我还注意到,传递到 addJSONData 的相同数据不适用于 addChildNode。我不确定这是设计使然还是只是疏忽。如果所有数据(父级和子级)在开始时立即传递到 addJSONData,则整个示例可以正常运行。任何帮助将不胜感激。
I'm currently working on getting a treegrid going where I'm overriding the data functions to call a thrift service to fill in the data. The idea is that I load only the parent nodes then when the node is expanded it will dynamically call the thrift service to fill in the data. I have run into some quirks with the way the treegrid is behaving when I try to load the children dynamically. It will load the initial list fine but when I go to dynamically load the child it's not adding it when the parent is expanded. Now if you expand the second entry it add the child to the list in the correct position but it doesn't see it as a child of 287.
I can't seem to grasp what I'm doing wrong with it that it doesn't want to properly add as a child.
// The data that is returned via thrift to fill in the initial entry in the table
{
"total" : "13″,
"page":"1″,
"records": "720″,
"rows" : [
{"id" : "287","cell" : ["287","MDXX00025",true,0,null,false,false] }
,{"id" : "544″,"isLeaf":true,"cell" : ["544","MDXX00460",true,0,null,false,false] }]
}
// How jqGrid is configured with a oData object that contains the child I want to fill in.
var oData = { "rows" : [
{"id" : "7220","parent":287,"level":"1","isLeaf":true,"loaded":true,"empty":"MDXX00450" }]
};
function DoWork(postdata)
{
var sData = client.NavigateTable(postdata._search,postdata.page,postdata.rows,postdata.sidx,
postdata.sord,postdata.totalrows);
var obj = jQuery.parseJSON(sData);
var thegrid = jQuery("#addtree")[0];
thegrid.addJSONData(obj);
}
function DoTreeWork(postdata)
{
var thegrid = $("#addtree");
thegrid.jqGrid ('addChildNode', oData.rows[0].id, oData.rows[0].parent, oData.rows[0]);
}
jQuery(document).ready(function(){
$.jgrid.defaults = $.extend($.jgrid.defaults,{loadui:"enable"});
jQuery("#addtree").jqGrid({
datatype: function(postdata)
{
DoWork(postdata);
},
treedatatype: function (postdata)
{
DoTreeWork(postdata);
},
treeGrid: true,
treeGridModel: 'adjacency',
colNames:["id","empty","docno,"],
colModel:[
{name:'id',index:'id', width:20,key:true, editable:false},
{name:'empty',index:'empty',width:10},
{name:'docno',index:'docno', width:30, editable:true}
],
pager : "#paddtree",
treeGrid: true,
ExpandColumn : 'name',
editurl:'server.asp',
viewrecords: true,
autowidth: true,
height:'400',
rowNum:52,
rowTotal:100,
gridview: true,
sortorder: "asc",
sortname: 'id',
caption: "Grid"
});
jQuery("#addtree").jqGrid('navGrid',"#paddtree",{edit:true,add:false,del:true,search:false});
});
I have also noted that the same data passed into addJSONData will not work with the addChildNode. I'm not sure if this is by design or just an oversight. This whole example functions fine if all the data (parents and children) is passed at once at the beginning to addJSONData. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有类似的问题。当我删除树节点时,我使用 AddChildNode 添加子节点。但它不能正常工作。父级(删除的行)和子级(在 ondrop 事件中添加的行)之间的关系不起作用。作为解决方案,您可以删除删除的行并添加父节点和子节点。
I am having similar issue. when I drop a tree node, I add child nodes to it using AddChildNode. but it is not working properly. The relationship between parent(dropped row) and child ( added rows in ondrop event) is not working. As a workaround solution , you delete dropped rows and add parent and child nodes.