]> git.proxmox.com Git - extjs.git/blame - extjs/examples/kitchensink/classic/samples/view/grid/GroupedGrid.js
add extjs 6.0.1 sources
[extjs.git] / extjs / examples / kitchensink / classic / samples / view / grid / GroupedGrid.js
CommitLineData
6527f429
DM
1/**\r
2 * This example illustrates how to use the grouping feature of the Grid.\r
3 */\r
4Ext.define('KitchenSink.view.grid.GroupedGrid', {\r
5 extend: 'Ext.grid.Panel',\r
6 xtype: 'grouped-grid',\r
7 requires: [\r
8 'Ext.grid.feature.Grouping'\r
9 ],\r
10 collapsible: true,\r
11 frame: true,\r
12 width: 600,\r
13 height: 400,\r
14\r
15 // Need a minHeight. Neptune resizable framed panels are overflow:visible so as to\r
16 // enable resizing handles to be embedded in the border lines.\r
17 minHeight: 200,\r
18 title: 'Restaurants',\r
19 resizable: true,\r
20\r
21 features: [{\r
22 ftype: 'grouping',\r
23 groupHeaderTpl: '{columnName}: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',\r
24 hideGroupedHeader: true,\r
25 startCollapsed: true,\r
26 id: 'restaurantGrouping'\r
27 }],\r
28 //<example>\r
29 otherContent: [{\r
30 type: 'Store',\r
31 path: 'classic/samples/store/Restaurants.js'\r
32 },{\r
33 type: 'Model',\r
34 path: 'classic/samples/model/Restaurant.js'\r
35 }],\r
36 profiles: {\r
37 classic: {\r
38 },\r
39 neptune: {\r
40 }\r
41 },\r
42 //</example>\r
43\r
44 initComponent: function() {\r
45 this.store = new KitchenSink.store.Restaurants();\r
46 this.columns = [{\r
47 text: 'Name',\r
48 flex: 1,\r
49 dataIndex: 'name'\r
50 },{\r
51 text: 'Cuisine',\r
52 flex: 1,\r
53 dataIndex: 'cuisine'\r
54 }];\r
55\r
56 this.callParent();\r
57\r
58 var store = this.getStore(),\r
59 toggleMenu = [];\r
60\r
61 this.groupingFeature = this.view.getFeature('restaurantGrouping');\r
62\r
63 // Create checkbox menu items to toggle associated group\r
64 store.getGroups().each(function(group) {\r
65 toggleMenu.push({\r
66 xtype: 'menucheckitem',\r
67 text: group.getGroupKey(),\r
68 handler: this.toggleGroup,\r
69 scope: this\r
70 });\r
71 }, this);\r
72\r
73 this.addDocked([{\r
74 xtype: 'toolbar',\r
75 items: ['->', {\r
76 text: 'Toggle groups...',\r
77 destroyMenu: true,\r
78 menu: toggleMenu\r
79 }]\r
80 }, {\r
81 xtype: 'toolbar',\r
82 ui: 'footer',\r
83 dock: 'bottom',\r
84 items: ['->', {\r
85 text:'Clear Grouping',\r
86 iconCls: 'icon-clear-group',\r
87 scope: this,\r
88 handler: this.onClearGroupingClick\r
89 }]\r
90 }]);\r
91\r
92 this.mon(this.store, 'groupchange', this.onGroupChange, this);\r
93 this.mon(this.view, {\r
94 groupcollapse: this.onGroupCollapse,\r
95 groupexpand: this.onGroupExpand,\r
96 scope: this\r
97 });\r
98 },\r
99\r
100 onClearGroupingClick: function(){\r
101 this.groupingFeature.disable();\r
102 },\r
103\r
104 toggleGroup: function(item) {\r
105 var groupName = item.text;\r
106 if (item.checked) {\r
107 this.groupingFeature.expand(groupName, true);\r
108 } else {\r
109 this.groupingFeature.collapse(groupName, true);\r
110 }\r
111 },\r
112\r
113 onGroupChange: function(store, grouper) {\r
114 var grouped = store.isGrouped(),\r
115 groupBy = grouper ? grouper.getProperty() : '',\r
116 toggleMenuItems, len, i = 0;\r
117\r
118 // Clear grouping button only valid if the store is grouped\r
119 this.down('[text=Clear Grouping]').setDisabled(!grouped);\r
120\r
121 // Sync state of group toggle checkboxes\r
122 if (grouped && groupBy === 'cuisine') {\r
123 toggleMenuItems = this.down('button[text=Toggle groups...]').menu.items.items;\r
124 for (len = toggleMenuItems.length; i < len; i++) {\r
125 toggleMenuItems[i].setChecked(\r
126 this.groupingFeature.isExpanded(toggleMenuItems[i].text)\r
127 );\r
128 }\r
129 this.down('[text=Toggle groups...]').enable();\r
130 } else {\r
131 this.down('[text=Toggle groups...]').disable();\r
132 }\r
133 },\r
134\r
135 onGroupCollapse: function(v, n, groupName) {\r
136 if (!this.down('[text=Toggle groups...]').disabled) {\r
137 this.down('menucheckitem[text=' + groupName + ']').setChecked(false, true);\r
138 }\r
139 },\r
140\r
141 onGroupExpand: function(v, n, groupName) {\r
142 if (!this.down('[text=Toggle groups...]').disabled) {\r
143 this.down('menucheckitem[text=' + groupName + ']').setChecked(true, true);\r
144 }\r
145 }\r
146});\r