treegrid.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Ext.Loader.setConfig({
  2. enabled: true
  3. });Ext.Loader.setPath('Ext.ux', '../ux');
  4. Ext.require([
  5. 'Ext.data.*',
  6. 'Ext.grid.*',
  7. 'Ext.tree.*',
  8. 'Ext.ux.CheckColumn'
  9. ]);
  10. Ext.onReady(function() {
  11. Ext.QuickTips.init();
  12. //we want to setup a model and store instead of using dataUrl
  13. Ext.define('Task', {
  14. extend: 'Ext.data.Model',
  15. fields: [
  16. {name: 'task', type: 'string'},
  17. {name: 'user', type: 'string'},
  18. {name: 'duration', type: 'string'},
  19. {name: 'done', type: 'boolean'}
  20. ]
  21. });
  22. var store = Ext.create('Ext.data.TreeStore', {
  23. model: 'Task',
  24. proxy: {
  25. type: 'ajax',
  26. //the store will get the content from the .json file
  27. url: 'treegrid.json'
  28. },
  29. folderSort: true
  30. });
  31. //Ext.ux.tree.TreeGrid is no longer a Ux. You can simply use a tree.TreePanel
  32. var tree = Ext.create('Ext.tree.Panel', {
  33. title: 'Core Team Projects',
  34. width: 500,
  35. height: 300,
  36. renderTo: Ext.getBody(),
  37. collapsible: true,
  38. useArrows: true,
  39. rootVisible: false,
  40. store: store,
  41. multiSelect: true,
  42. singleExpand: true,
  43. //the 'columns' property is now 'headers'
  44. columns: [{
  45. xtype: 'treecolumn', //this is so we know which column will show the tree
  46. text: 'Task',
  47. flex: 2,
  48. sortable: true,
  49. dataIndex: 'task'
  50. },{
  51. //we must use the templateheader component so we can use a custom tpl
  52. xtype: 'templatecolumn',
  53. text: 'Duration',
  54. flex: 1,
  55. sortable: true,
  56. dataIndex: 'duration',
  57. align: 'center',
  58. //add in the custom tpl for the rows
  59. tpl: Ext.create('Ext.XTemplate', '{duration:this.formatHours}', {
  60. formatHours: function(v) {
  61. if (v < 1) {
  62. return Math.round(v * 60) + ' mins';
  63. } else if (Math.floor(v) !== v) {
  64. var min = v - Math.floor(v);
  65. return Math.floor(v) + 'h ' + Math.round(min * 60) + 'm';
  66. } else {
  67. return v + ' hour' + (v === 1 ? '' : 's');
  68. }
  69. }
  70. })
  71. },{
  72. text: 'Assigned To',
  73. flex: 1,
  74. dataIndex: 'user',
  75. sortable: true
  76. }, {
  77. xtype: 'checkcolumn',
  78. header: 'Done',
  79. dataIndex: 'done',
  80. width: 40,
  81. stopSelection: false
  82. }, {
  83. text: 'Edit',
  84. width: 40,
  85. menuDisabled: true,
  86. xtype: 'actioncolumn',
  87. tooltip: 'Edit task',
  88. align: 'center',
  89. icon: '../simple-tasks/resources/images/edit_task.png',
  90. handler: function(grid, rowIndex, colIndex, actionItem, event, record, row) {
  91. Ext.Msg.alert('Editing' + (record.get('done') ? ' completed task' : '') , record.get('task'));
  92. }
  93. }]
  94. });
  95. });