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