Jqgrid 树视图邻接
我在 ma 应用程序中使用 Jqgrid 树视图模型,我可以看到它显示错误,因为不支持对象或属性,我已包含 grid.Treeview.js 和其他 Jqgrid 脚本文件。我不知道可能是什么问题。 当我在net中检查邻接树视图的示例应用程序时,我尝试了同样的操作,但在asp.net中使用了我没有得到的本地数据。任何人都可以帮助我如何做同样的事情。 预先感谢
这是我使用的示例代码,而且我不知道它是否有效。
var myTreeGrid = new Ext.us.tree.TreeGrid({
columns: columnsConfig,
rootVisible: false,
root: rootNode,
loader: new Ext.ux.tree.TreeGridLoader({preloadChildren: true})
});
var rootNode = $('#treegridsamp').jqgrid({
treeGrid: true,
treeGridModel: 'adjacecncy',
ExpandColumn: 'name',
datatype: "local",
mtype: 'Get',
colNames: ['id','Name','MenuId','Menu Name'],
colModel: [
{name:'RowId',index:'RowId',width:300,fixed:true},
{name:'Name',index:'Name',width:300,fixed:true},
{name:'MenuId',index:'MenuId',width:300,fixed:true},
{name:'MenuName',index:'MenuName',width:300,fixed:true},
],
root:[
{id:"1",Name:"Main Menu", MenuId:"1",MenuName:"Menu1"},
{id:"2",Name:"Main Menu1",MenuId:"2",MenuName:"Menu2"},
{id:"3",Name:"Main Menu2",MenuId:"3",MenuName:"Menu3"}
],
pager: '#dvtreegridsamp',
Caption: 'Sample Tree View Model'
})
$("#treegridsamp").jqGrid('navGrid', '#dvtreegridsamp',
{ edit: false, add: false, del: false, search: false, refresh: false });
var mydata=[
{id:"1", Name:"Main Menu", MenuId:"1",MenuName:"Menu1"},
{id:"2", Name:"Main Menu1", MenuId:"2",MenuName:"Menu2"},
{id:"3", Name:"Main Menu2", MenuId:"3",MenuName:"Menu3"},
{id:"1.1", Name:"Sub Menu", MenuId:"1",MenuName:"Menu1"},
{id:"1.2", Name:"Sub Menu1", MenuId:"1",MenuName:"Menu1"},
{id:"1.1.1",Name:"Sub Sub Menu",MenuId:"1",MenuName:"Menu1"},
{id:"2.1", Name:"Main Menu", MenuId:"2",MenuName:"Menu2"},
{id:"2.2", Name:"Main Menu", MenuId:"2",MenuName:"Menu2"},
{id:"3.1", Name:"Main Menu", MenuId:"3",MenuName:"Menu3"},
{id:"3.2", Name:"Main Menu", MenuId:"3",MenuName:"Menu3"},
];
for(var i=0;i<mydata.length;i++) {
$("#treegridsamp").jqGrid('addRowData',i+1,mydata[i]);
}
I am using Jqgrid Tree View model in ma application and what i can see is that it shows error as object or property is not supported i have included grid.Treeview.js and other Jqgrid script file. I dont know what can be the issue.
And when i checked the sample application in net for adjacency tree view and i tried the same thing but in asp.net with local data which i did not get. Can any one help me how to do the same.
Thanks in advance
This is the sample code that im using and more over i dont whether will it work or not.
var myTreeGrid = new Ext.us.tree.TreeGrid({
columns: columnsConfig,
rootVisible: false,
root: rootNode,
loader: new Ext.ux.tree.TreeGridLoader({preloadChildren: true})
});
var rootNode = $('#treegridsamp').jqgrid({
treeGrid: true,
treeGridModel: 'adjacecncy',
ExpandColumn: 'name',
datatype: "local",
mtype: 'Get',
colNames: ['id','Name','MenuId','Menu Name'],
colModel: [
{name:'RowId',index:'RowId',width:300,fixed:true},
{name:'Name',index:'Name',width:300,fixed:true},
{name:'MenuId',index:'MenuId',width:300,fixed:true},
{name:'MenuName',index:'MenuName',width:300,fixed:true},
],
root:[
{id:"1",Name:"Main Menu", MenuId:"1",MenuName:"Menu1"},
{id:"2",Name:"Main Menu1",MenuId:"2",MenuName:"Menu2"},
{id:"3",Name:"Main Menu2",MenuId:"3",MenuName:"Menu3"}
],
pager: '#dvtreegridsamp',
Caption: 'Sample Tree View Model'
})
$("#treegridsamp").jqGrid('navGrid', '#dvtreegridsamp',
{ edit: false, add: false, del: false, search: false, refresh: false });
var mydata=[
{id:"1", Name:"Main Menu", MenuId:"1",MenuName:"Menu1"},
{id:"2", Name:"Main Menu1", MenuId:"2",MenuName:"Menu2"},
{id:"3", Name:"Main Menu2", MenuId:"3",MenuName:"Menu3"},
{id:"1.1", Name:"Sub Menu", MenuId:"1",MenuName:"Menu1"},
{id:"1.2", Name:"Sub Menu1", MenuId:"1",MenuName:"Menu1"},
{id:"1.1.1",Name:"Sub Sub Menu",MenuId:"1",MenuName:"Menu1"},
{id:"2.1", Name:"Main Menu", MenuId:"2",MenuName:"Menu2"},
{id:"2.2", Name:"Main Menu", MenuId:"2",MenuName:"Menu2"},
{id:"3.1", Name:"Main Menu", MenuId:"3",MenuName:"Menu3"},
{id:"3.2", Name:"Main Menu", MenuId:"3",MenuName:"Menu3"},
];
for(var i=0;i<mydata.length;i++) {
$("#treegridsamp").jqGrid('addRowData',i+1,mydata[i]);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您编写了一些简单的小错误,但您遇到的主要问题是您的代码是为了添加简单的行而不是树节点。您可以进入官方演示页面并在“New in version 3.4”下选择演示“树网格邻接模型”。
我编写了演示,其工作原理与演示中的演示完全相同trirand 演示页面,但仅使用本地数据:
如果您必须使用属性
level
、parent
、isLeaf
、expanded
扩展mydata
中的对象code>:这里我修改了一点 id 值,因为 ids 中不应该使用点。另外,我将“Main Menu1”的
expanded
状态设置为true
只是为了演示您可以在加载后立即自动展开某些节点。我将 jqGrid 定义修改为以下内容,
隐藏“id”列并减小网格大小。要添加数据,我使用了
addJSONData
方法,因为它将设置树节点,结果您将收到
您可以此处观看演示。
更新:如果您使用 jqGrid 版本 4.0 或更高版本,如果您想要扩展,请务必为树节点设置
loaded:true
属性。例如,在上面的示例中,“Main Menu1”项是一个节点 (isLeaf:false
),应展开显示 (expanded:true
),因此应添加 < code>loaded:true 用于项目定义:有关更多示例,请参阅 此处,此处,此处和这里< /a>.
更新 2:要正确排序,必须使用
parent:null
或parent:"null"
而不是父级:“”
请参阅此处了解更多详细信息。You code small simple errors, but the main problem which you have is that your code are made to add simple rows and not tree nodes. You can go on the official demo page and choose under "New in version 3.4" the demo "Tree Grid Adjacency model".
I wrote the demo which work exactly like the demo from the demo from the trirand demo page, but use only local data:
In you case you have to extend the objects from
mydata
with the propertieslevel
,parent
,isLeaf
,expanded
:Here I modified a little id values, because points should not used in ids. Additionally I set the
expanded
status of the "Main Menu1" totrue
to demonstrate only that you can expanded some nodes automatically immediately after the loading.I modified the jqGrid definition to the following
I made the 'id' column hidden and reduced the grid size. To add the data I used
addJSONData
method because it will set the tree nodesAs the result you will receive
You can see the demo live here.
UPDATED: If you use jqGrid version 4.0 or higher it is important to set
loaded:true
property for the tree nodes if you want have expanded. For example in the above example the "Main Menu1" item is a node (isLeaf:false
) which should be display expanded (expanded:true
), so one should addloaded:true
for the item definition:For more examples see here, here, here and here.
UPDATED 2: To have sorting work correctly one have to use
parent:null
orparent:"null"
instead ofparent:""
see here for more details.