]> git.proxmox.com Git - extjs.git/blame - extjs/build/examples/kitchensink/classic/samples/view/grid/Reconfigure.js
add extjs 6.0.1 sources
[extjs.git] / extjs / build / examples / kitchensink / classic / samples / view / grid / Reconfigure.js
CommitLineData
6527f429
DM
1/**\r
2 * This example shows how a grid can have its store and columns reconfigured dynamically.\r
3 * By default, we start with no store or columns, we can define them later using the\r
4 * reconfigure method.\r
5 */\r
6Ext.define('KitchenSink.view.grid.Reconfigure', {\r
7 extend: 'Ext.container.Container',\r
8 \r
9 requires: [\r
10 'Ext.grid.*',\r
11 'Ext.layout.container.HBox',\r
12 'Ext.layout.container.VBox',\r
13 'KitchenSink.model.grid.Office',\r
14 'KitchenSink.model.grid.Employee'\r
15 ], \r
16 xtype: 'reconfigure-grid',\r
17 \r
18 //<example>\r
19 exampleTitle: 'Grid Reconfigure',\r
20 profiles: {\r
21 classic: {\r
22 employeeWidth: 100 \r
23 },\r
24 neptune: {\r
25 employeeWidth: 130\r
26 }\r
27 },\r
28 //</example>\r
29 \r
30 layout: {\r
31 type: 'vbox',\r
32 align: 'stretch'\r
33 },\r
34 \r
35 width: 500,\r
36 height: 330,\r
37 \r
38 lastNames: ['Jones', 'Smith', 'Lee', 'Wilson', 'Black', 'Williams', 'Lewis', 'Johnson', 'Foot', 'Little', 'Vee', 'Train', 'Hot', 'Mutt'],\r
39 firstNames: ['Fred', 'Julie', 'Bill', 'Ted', 'Jack', 'John', 'Mark', 'Mike', 'Chris', 'Bob', 'Travis', 'Kelly', 'Sara'],\r
40 cities: ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Philadelphia', 'Phoenix', 'San Antonio', 'San Diego', 'Dallas', 'San Jose'],\r
41 departments: ['Development', 'QA', 'Marketing', 'Accounting', 'Sales'],\r
42 \r
43 initComponent: function(){\r
44 Ext.apply(this, {\r
45 items: [{\r
46 xtype: 'container',\r
47 layout: 'hbox',\r
48 defaultType: 'button',\r
49 items: [{\r
50 itemId: 'showOffices',\r
51 text: 'Show Offices',\r
52 scope: this,\r
53 handler: this.onShowOfficesClick\r
54 }, {\r
55 itemId: 'showEmployees',\r
56 margin: '0 0 0 10',\r
57 text: 'Show Employees',\r
58 scope: this,\r
59 handler: this.onShowEmployeesClick\r
60 }]\r
61 }, {\r
62 margin: '10 0 0 0',\r
63 xtype: 'grid',\r
64 flex: 1,\r
65 columns: [],\r
66 viewConfig: {\r
67 emptyText: 'Click a button to show a dataset',\r
68 deferEmptyText: false\r
69 }\r
70 }] \r
71 });\r
72 this.callParent();\r
73 },\r
74 \r
75 onShowOfficesClick: function(){\r
76 var grid = this.down('grid');\r
77 \r
78 Ext.suspendLayouts();\r
79 grid.setTitle('Offices');\r
80 grid.reconfigure(this.createOfficeStore(), [{\r
81 flex: 1,\r
82 text: 'City',\r
83 dataIndex: 'city'\r
84 }, {\r
85 text: 'Total Employees',\r
86 dataIndex: 'totalEmployees',\r
87 width: 140\r
88 }, {\r
89 text: 'Manager',\r
90 dataIndex: 'manager',\r
91 width: 120\r
92 }]);\r
93 this.down('#showEmployees').enable();\r
94 this.down('#showOffices').disable();\r
95 Ext.resumeLayouts(true); \r
96 },\r
97 \r
98 onShowEmployeesClick: function(){\r
99 var grid = this.down('grid');\r
100 \r
101 Ext.suspendLayouts();\r
102 grid.setTitle('Employees');\r
103 grid.reconfigure(this.createEmployeeStore(), [{\r
104 text: 'First Name',\r
105 dataIndex: 'forename'\r
106 }, {\r
107 text: 'Last Name',\r
108 dataIndex: 'surname'\r
109 }, {\r
110 width: this.profileInfo.employeeWidth,\r
111 text: 'Employee No.',\r
112 dataIndex: 'employeeNo'\r
113 }, {\r
114 flex: 1,\r
115 text: 'Department',\r
116 dataIndex: 'department'\r
117 }]);\r
118 this.down('#showOffices').enable();\r
119 this.down('#showEmployees').disable();\r
120 Ext.resumeLayouts(true);\r
121 },\r
122 \r
123 createEmployeeStore: function(){\r
124 var data = [],\r
125 i = 0,\r
126 usedNames = {},\r
127 name;\r
128 \r
129 for (; i < 20; ++i) {\r
130 name = this.getUniqueName(usedNames);\r
131 data.push({\r
132 forename: name[0],\r
133 surname: name[1],\r
134 employeeNo: this.getEmployeeNo(),\r
135 department: this.getDepartment()\r
136 });\r
137 }\r
138 return new Ext.data.Store({\r
139 model: KitchenSink.model.grid.Employee,\r
140 data: data\r
141 });\r
142 },\r
143 \r
144 createOfficeStore: function(){\r
145 var data = [],\r
146 i = 0,\r
147 usedNames = {},\r
148 usedCities = {};\r
149 \r
150 for (; i < 7; ++i) {\r
151 data.push({\r
152 city: this.getUniqueCity(usedCities),\r
153 manager: this.getUniqueName(usedNames).join(' '),\r
154 totalEmployees: Ext.Number.randomInt(10, 25)\r
155 });\r
156 }\r
157 return new Ext.data.Store({\r
158 model: KitchenSink.model.grid.Office,\r
159 data: data\r
160 });\r
161 },\r
162 \r
163 // Fake data generation functions\r
164 generateName: function(){\r
165 var lasts = this.lastNames,\r
166 firsts = this.firstNames,\r
167 lastLen = lasts.length,\r
168 firstLen = firsts.length,\r
169 getRandomInt = Ext.Number.randomInt,\r
170 first = firsts[getRandomInt(0, firstLen - 1)],\r
171 last = lasts[getRandomInt(0, lastLen - 1)];\r
172 \r
173 return [first, last];\r
174 },\r
175 \r
176 getUniqueName: function(used) {\r
177 var name = this.generateName(),\r
178 key = name[0] + name[1];\r
179 \r
180 if (used[key]) {\r
181 return this.getUniqueName(used);\r
182 }\r
183 \r
184 used[key] = true;\r
185 return name;\r
186 },\r
187 \r
188 getCity: function(){\r
189 var cities = this.cities,\r
190 len = cities.length;\r
191 \r
192 return cities[Ext.Number.randomInt(0, len - 1)];\r
193 },\r
194 \r
195 getUniqueCity: function(used){\r
196 var city = this.getCity();\r
197 if (used[city]) {\r
198 return this.getUniqueCity(used);\r
199 }\r
200 \r
201 used[city] = true;\r
202 return city;\r
203 },\r
204 \r
205 getEmployeeNo: function() {\r
206 var out = '',\r
207 i = 0;\r
208 for (; i < 6; ++i) {\r
209 out += Ext.Number.randomInt(0, 7);\r
210 }\r
211 return out;\r
212 },\r
213 \r
214 getDepartment: function() {\r
215 var departments = this.departments,\r
216 len = departments.length;\r
217 \r
218 return departments[Ext.Number.randomInt(0, len - 1)];\r
219 }\r
220});