ExtJS4学习笔记(十九)---TreeGrid

本文介绍如何使用Extjs4 TreeGrid实现多表头、AJAX数据加载、排序等功能。通过具体实例展示了如何配置TreeGrid,包括设置模型、创建数据存储、定义列头等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文介绍Extjs4 TreeGrid的使用,实例中的树实现了多表头、使用AJAX请求载入数据、排序,隐藏和显示表头等Grid中的功能。实例来自Extjs官方网站

HTML代码:

  1. <divid="tree-example"></div>

JS代码:

  1. Ext.require([
  2. 'Ext.data.*',
  3. 'Ext.grid.*',
  4. 'Ext.tree.*'
  5. ]);

  6. Ext.onReady(function(){
  7. //wewanttosetupamodelandstoreinsteadofusingdataUrl
  8. Ext.regModel('Task',{
  9. fields:[
  10. {name:'task',type:'string'},
  11. {name:'user',type:'string'},
  12. {name:'duration',type:'string'}
  13. ]
  14. });
  15. varstore=newExt.data.TreeStore({
  16. model:'Task',
  17. proxy:{
  18. type:'ajax',
  19. //thestorewillgetthecontentfromthe.jsonfile
  20. url:'treegrid.json'
  21. },
  22. root:{
  23. expanded:true
  24. }
  25. });
  26. //Ext.ux.tree.TreeGridisnolongeraUx.Youcansimplyuseatree.TreePanel
  27. vartree=newExt.tree.TreePanel({
  28. title:'CoreTeamProjects',
  29. width:500,
  30. height:300,
  31. renderTo:Ext.getBody(),

  32. useArrows:true,
  33. rootVisible:false,
  34. store:store,
  35. //the'columns'propertyisnow'headers'
  36. headers:[{
  37. xtype:'treeheader',//thisissoweknowwhichcolumnwillshowthetree
  38. text:'Task',
  39. flex:2,
  40. dataIndex:'task'
  41. },{
  42. //wemustusethetemplateheadercomponentsowecanuseacustomtpl
  43. xtype:'templateheader',
  44. text:'Duration',
  45. flex:1,
  46. dataIndex:'duration',
  47. align:'center',
  48. //addinthecustomtplfortherows
  49. tpl:newExt.XTemplate('{duration:this.formatHours}',{
  50. formatHours:function(v){
  51. if(v<1){
  52. returnMath.round(v*60)+'mins';
  53. }elseif(Math.floor(v)!==v){
  54. varmin=v-Math.floor(v);
  55. returnMath.floor(v)+'h'+Math.round(min*60)+'m';
  56. }else{
  57. returnv+'hour'+(v===1?'':'s');
  58. }
  59. }
  60. })
  61. },{
  62. text:'AssignedTo',
  63. flex:1,
  64. dataIndex:'user'
  65. }]
  66. });
  67. });

实例使用JSON数据格式,要求返回类似如下格式的数据:

  1. [{"text":".","children":[
  2. {
  3. task:'Project:Shopping',
  4. duration:13.25,
  5. user:'TommyMaintz',
  6. iconCls:'task-folder',
  7. expanded:true,
  8. children:[{
  9. task:'Housewares',
  10. duration:1.25,
  11. user:'TommyMaintz',
  12. iconCls:'task-folder',
  13. children:[{
  14. task:'Kitchensupplies',
  15. duration:0.25,
  16. user:'TommyMaintz',
  17. leaf:true,
  18. iconCls:'task'
  19. },{
  20. task:'Groceries',
  21. duration:.4,
  22. user:'TommyMaintz',
  23. leaf:true,
  24. iconCls:'task'
  25. },{
  26. task:'Cleaningsupplies',
  27. duration:.4,
  28. user:'TommyMaintz',
  29. leaf:true,
  30. iconCls:'task'
  31. },{
  32. task:'Officesupplies',
  33. duration:.2,
  34. user:'TommyMaintz',
  35. leaf:true,
  36. iconCls:'task'
  37. }]
  38. }]
  39. }]
  40. }]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值