]> git.proxmox.com Git - extjs.git/blame - extjs/build/examples/classic/menu/action-grid.js
add extjs 6.0.1 sources
[extjs.git] / extjs / build / examples / classic / menu / action-grid.js
CommitLineData
6527f429
DM
1Ext.require([\r
2 'Ext.grid.*',\r
3 'Ext.data.*',\r
4 'Ext.util.*',\r
5 'Ext.Action'\r
6]);\r
7\r
8Ext.onReady(function() {\r
9 Ext.QuickTips.init();\r
10\r
11 // sample static data for the store\r
12 var myData = [\r
13 ['3m Co', 71.72, 0.02, 0.03, '9/1 12:00am'],\r
14 ['Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am'],\r
15 ['Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am'],\r
16 ['American Express Company', 52.55, 0.01, 0.02, '9/1 12:00am'],\r
17 ['American International Group, Inc.', 64.13, 0.31, 0.49, '9/1 12:00am'],\r
18 ['AT&T Inc.', 31.61, -0.48, -1.54, '9/1 12:00am'],\r
19 ['Boeing Co.', 75.43, 0.53, 0.71, '9/1 12:00am'],\r
20 ['Caterpillar Inc.', 67.27, 0.92, 1.39, '9/1 12:00am'],\r
21 ['Citigroup, Inc.', 49.37, 0.02, 0.04, '9/1 12:00am'],\r
22 ['E.I. du Pont de Nemours and Company', 40.48, 0.51, 1.28, '9/1 12:00am'],\r
23 ['Exxon Mobil Corp', 68.1, -0.43, -0.64, '9/1 12:00am'],\r
24 ['General Electric Company', 34.14, -0.08, -0.23, '9/1 12:00am'],\r
25 ['General Motors Corporation', 30.27, 1.09, 3.74, '9/1 12:00am'],\r
26 ['Hewlett-Packard Co.', 36.53, -0.03, -0.08, '9/1 12:00am'],\r
27 ['Honeywell Intl Inc', 38.77, 0.05, 0.13, '9/1 12:00am'],\r
28 ['Intel Corporation', 19.88, 0.31, 1.58, '9/1 12:00am'],\r
29 ['International Business Machines', 81.41, 0.44, 0.54, '9/1 12:00am'],\r
30 ['Johnson & Johnson', 64.72, 0.06, 0.09, '9/1 12:00am'],\r
31 ['JP Morgan & Chase & Co', 45.73, 0.07, 0.15, '9/1 12:00am'],\r
32 ['McDonald\'s Corporation', 36.76, 0.86, 2.40, '9/1 12:00am'],\r
33 ['Merck & Co., Inc.', 40.96, 0.41, 1.01, '9/1 12:00am'],\r
34 ['Microsoft Corporation', 25.84, 0.14, 0.54, '9/1 12:00am'],\r
35 ['Pfizer Inc', 27.96, 0.4, 1.45, '9/1 12:00am'],\r
36 ['The Coca-Cola Company', 45.07, 0.26, 0.58, '9/1 12:00am'],\r
37 ['The Home Depot, Inc.', 34.64, 0.35, 1.02, '9/1 12:00am'],\r
38 ['The Procter & Gamble Company', 61.91, 0.01, 0.02, '9/1 12:00am'],\r
39 ['United Technologies Corporation', 63.26, 0.55, 0.88, '9/1 12:00am'],\r
40 ['Verizon Communications', 35.57, 0.39, 1.11, '9/1 12:00am'],\r
41 ['Wal-Mart Stores, Inc.', 45.45, 0.73, 1.63, '9/1 12:00am']\r
42 ];\r
43\r
44 /**\r
45 * Custom function used for column renderer\r
46 * @param {Object} val\r
47 */\r
48 function change(val) {\r
49 if (val > 0) {\r
50 return '<span style="color:green;">' + val + '</span>';\r
51 } else if (val < 0) {\r
52 return '<span style="color:red;">' + val + '</span>';\r
53 }\r
54 return val;\r
55 }\r
56\r
57 /**\r
58 * Custom function used for column renderer\r
59 * @param {Object} val\r
60 */\r
61 function pctChange(val) {\r
62 if (val > 0) {\r
63 return '<span style="color:green;">' + val + '%</span>';\r
64 } else if (val < 0) {\r
65 return '<span style="color:red;">' + val + '%</span>';\r
66 }\r
67 return val;\r
68 }\r
69\r
70 // create the data store\r
71 var store = Ext.create('Ext.data.ArrayStore', {\r
72 fields: [\r
73 {name: 'company'},\r
74 {name: 'price', type: 'float'},\r
75 {name: 'change', type: 'float'},\r
76 {name: 'pctChange', type: 'float'},\r
77 {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}\r
78 ],\r
79 data: myData\r
80 });\r
81\r
82 var sellAction = Ext.create('Ext.Action', {\r
83 icon : '../shared/icons/fam/delete.gif', // Use a URL in the icon config\r
84 text: 'Sell stock',\r
85 disabled: true,\r
86 handler: function(widget, event) {\r
87 var rec = grid.getSelectionModel().getSelection()[0];\r
88 if (rec) {\r
89 Ext.example.msg('Sell', 'Sell ' + rec.get('company'));\r
90 }\r
91 }\r
92 });\r
93 var buyAction = Ext.create('Ext.Action', {\r
94 iconCls: 'buy-button',\r
95 text: 'Buy stock',\r
96 disabled: true,\r
97 handler: function(widget, event) {\r
98 var rec = grid.getSelectionModel().getSelection()[0];\r
99 if (rec) {\r
100 Ext.example.msg('Buy', 'Buy ' + rec.get('company'));\r
101 }\r
102 }\r
103 });\r
104\r
105 var contextMenu = Ext.create('Ext.menu.Menu', {\r
106 items: [\r
107 buyAction,\r
108 sellAction\r
109 ]\r
110 });\r
111\r
112 // create the Grid\r
113 var grid = Ext.create('Ext.grid.Panel', {\r
114 store: store,\r
115 columnLines: true,\r
116 columns: [\r
117 {\r
118 text : 'Company',\r
119 flex : 1,\r
120 sortable : false,\r
121 dataIndex: 'company'\r
122 },\r
123 {\r
124 text : 'Price',\r
125 width : 75,\r
126 sortable : true,\r
127 formatter: 'usMoney',\r
128 dataIndex: 'price'\r
129 },\r
130 {\r
131 text : 'Change',\r
132 width : 75,\r
133 sortable : true,\r
134 renderer : change,\r
135 dataIndex: 'change'\r
136 },\r
137 {\r
138 text : '% Change',\r
139 width : 75,\r
140 sortable : true,\r
141 renderer : pctChange,\r
142 dataIndex: 'pctChange'\r
143 },\r
144 {\r
145 text : 'Last Updated',\r
146 width : 85,\r
147 sortable : true,\r
148 formatter: 'date("m/d/Y")',\r
149 dataIndex: 'lastChange'\r
150 }\r
151 ],\r
152 dockedItems: [{\r
153 xtype: 'toolbar',\r
154 items: [\r
155 buyAction, sellAction\r
156 ]\r
157 }],\r
158 viewConfig: {\r
159 stripeRows: true,\r
160 listeners: {\r
161 itemcontextmenu: function(view, rec, node, index, e) {\r
162 e.stopEvent();\r
163 contextMenu.showAt(e.getXY());\r
164 return false;\r
165 }\r
166 }\r
167 },\r
168 height: 350,\r
169 width: 600,\r
170 title: 'Action Grid',\r
171 renderTo: 'grid-example',\r
172 stateful: false\r
173 });\r
174\r
175 grid.getSelectionModel().on({\r
176 selectionchange: function(sm, selections) {\r
177 if (selections.length) {\r
178 buyAction.enable();\r
179 sellAction.enable();\r
180 } else {\r
181 buyAction.disable();\r
182 sellAction.disable();\r
183 }\r
184 }\r
185 });\r
186});\r