3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
7 Ext.onReady(function(){
\r
8 Ext.QuickTips.init();
\r
10 var Employee = Ext.data.Record.create([{
\r
29 // hideous function to generate employee data
\r
30 var genData = function(){
\r
32 var s = new Date(2007, 0, 1);
\r
33 var now = new Date(), i = -1;
\r
34 while(s.getTime() < now.getTime()){
\r
35 var ecount = Ext.ux.getRandomInt(0, 3);
\r
36 for(var i = 0; i < ecount; i++){
\r
37 var name = Ext.ux.generateName();
\r
39 start : s.clearTime(true).add(Date.DAY, Ext.ux.getRandomInt(0, 27)),
\r
41 email: name.toLowerCase().replace(' ', '.') + '@exttest.com',
\r
43 salary: Math.floor(Ext.ux.getRandomInt(35000, 85000)/1000)*1000
\r
46 s = s.add(Date.MONTH, 1);
\r
52 var store = new Ext.data.GroupingStore({
\r
53 reader: new Ext.data.JsonReader({fields: Employee}),
\r
55 sortInfo: {field: 'start', direction: 'ASC'}
\r
58 var editor = new Ext.ux.grid.RowEditor({
\r
62 var grid = new Ext.grid.GridPanel({
\r
67 autoExpandColumn: 'name',
\r
69 view: new Ext.grid.GroupingView({
\r
73 iconCls: 'icon-user-add',
\r
74 text: 'Add Employee',
\r
75 handler: function(){
\r
76 var e = new Employee({
\r
78 email: 'new@exttest.com',
\r
79 start: (new Date()).clearTime(),
\r
83 editor.stopEditing();
\r
85 grid.getView().refresh();
\r
86 grid.getSelectionModel().selectRow(0);
\r
87 editor.startEditing(0);
\r
90 ref: '../removeBtn',
\r
91 iconCls: 'icon-user-delete',
\r
92 text: 'Remove Employee',
\r
94 handler: function(){
\r
95 editor.stopEditing();
\r
96 var s = grid.getSelectionModel().getSelections();
\r
97 for(var i = 0, r; r = s[i]; i++){
\r
104 new Ext.grid.RowNumberer(),
\r
107 header: 'First Name',
\r
112 xtype: 'textfield',
\r
117 dataIndex: 'email',
\r
121 xtype: 'textfield',
\r
126 xtype: 'datecolumn',
\r
127 header: 'Start Date',
\r
128 dataIndex: 'start',
\r
132 groupRenderer: Ext.util.Format.dateRenderer('M y'),
\r
134 xtype: 'datefield',
\r
136 minValue: '01/01/2006',
\r
137 minText: 'Can\'t have a start date before the company existed!',
\r
138 maxValue: (new Date()).format('m/d/Y')
\r
141 xtype: 'numbercolumn',
\r
143 dataIndex: 'salary',
\r
148 xtype: 'numberfield',
\r
154 xtype: 'booleancolumn',
\r
156 dataIndex: 'active',
\r
167 var cstore = new Ext.data.JsonStore({
\r
168 fields:['month', 'employees', 'salary'],
\r
170 refreshData: function(){
\r
171 var o = {}, data = [];
\r
172 var s = new Date(2007, 0, 1);
\r
173 var now = new Date(), i = -1;
\r
174 while(s.getTime() < now.getTime()){
\r
176 month: s.format('M y'),
\r
183 s = s.add(Date.MONTH, 1);
\r
185 store.each(function(r){
\r
186 var m = o[r.data.start.format('M y')];
\r
187 for(var i = m.index, mo; mo = data[i]; i++){
\r
188 mo.employees += 10000;
\r
189 mo.salary += r.data.salary;
\r
192 this.loadData(data);
\r
195 cstore.refreshData();
\r
196 store.on('add', cstore.refreshData, cstore);
\r
197 store.on('remove', cstore.refreshData, cstore);
\r
198 store.on('update', cstore.refreshData, cstore);
\r
200 var chart = new Ext.Panel({
\r
211 xtype: 'columnchart',
\r
213 url:'../../resources/charts.swf',
\r
215 yAxis: new Ext.chart.NumericAxis({
\r
216 displayName: 'Employees',
\r
217 labelRenderer : Ext.util.Format.numberRenderer('0,0')
\r
219 tipRenderer : function(chart, record, index, series){
\r
220 if(series.yField == 'salary'){
\r
221 return Ext.util.Format.number(record.data.salary, '$0,0') + ' total salary in ' + record.data.month;
\r
223 return Ext.util.Format.number(Math.floor(record.data.employees/10000), '0,0') + ' total employees in ' + record.data.month;
\r
227 // style chart so it looks pretty
\r
230 animationEnabled: true,
\r
255 majorTicks: {color: 0x69aBc8, length: 4},
\r
256 minorTicks: {color: 0x69aBc8, length: 2},
\r
257 majorGridLines: {size: 1, color: 0xeeeeee}
\r
261 majorTicks: {color: 0x69aBc8, length: 4},
\r
262 minorTicks: {color: 0x69aBc8, length: 2},
\r
263 majorGridLines: {size: 1, color: 0xdfe8f6}
\r
268 displayName: 'Salary',
\r
271 image:'../chart/bar.gif',
\r
280 var layout = new Ext.Panel({
\r
281 title: 'Employee Salary by Month',
\r
288 items: [chart, grid]
\r
290 layout.render(Ext.getBody());
\r
292 grid.getSelectionModel().on('selectionchange', function(sm){
\r
293 grid.removeBtn.setDisabled(sm.getCount() < 1);
\r