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
| Ext.define('KitchenSink.view.grid.ArrayGrid', {
| extend: 'Ext.grid.Panel',
| requires: [
| 'Ext.grid.column.Action'
| ],
| xtype: 'array-grid',
| store: 'Companies',
| stateful: true,
| collapsible: true,
| multiSelect: true,
| stateId: 'stateGrid',
| height: 350,
| title: 'Array Grid',
| viewConfig: {
| stripeRows: true,
| enableTextSelection: true
| },
| //<example>
| exampleDescription: [
| '<p>This example shows how to create a grid from Array data.</p>',
| '<p>The grid is stateful so you can move or hide columns, reload the page,',
| 'and come back to the grid in the same state you left it in.</p>',
| '<p>The cells are selectable due to use of the <code>enableTextSelection</code> ',
| 'option.</p>'
| ],
| themes: {
| classic: {
| width: 600,
| percentChangeColumnWidth: 75,
| lastUpdatedColumnWidth: 85,
| green: 'green',
| red: 'red'
| },
| neptune: {
| width: 650,
| percentChangeColumnWidth: 100,
| lastUpdatedColumnWidth: 115,
| green: '#73b51e',
| red: '#cf4c35'
| }
| },
| //</example>
|
| initComponent: function () {
| this.width = this.themeInfo.width;
| this.columns = [
| {
| text : 'Company',
| flex : 1,
| sortable : false,
| dataIndex: 'company'
| },
| {
| text : 'Price',
| width : 75,
| sortable : true,
| renderer : 'usMoney',
| dataIndex: 'price'
| },
| {
| text : 'Change',
| width : 80,
| sortable : true,
| renderer : function(val) {
| if (val > 0) {
| return '<span style="color:' + this.themeInfo.green + ';">' + val + '</span>';
| } else if (val < 0) {
| return '<span style="color:' + this.themeInfo.red + ';">' + val + '</span>';
| }
| return val;
| },
| dataIndex: 'change'
| },
| {
| text : '% Change',
| width : this.themeInfo.percentChangeColumnWidth,
| sortable : true,
| renderer : function(val) {
| if (val > 0) {
| return '<span style="color:' + this.themeInfo.green + '">' + val + '%</span>';
| } else if (val < 0) {
| return '<span style="color:' + this.themeInfo.red + ';">' + val + '%</span>';
| }
| return val;
| },
| dataIndex: 'pctChange'
| },
| {
| text : 'Last Updated',
| width : this.themeInfo.lastUpdatedColumnWidth,
| sortable : true,
| renderer : Ext.util.Format.dateRenderer('m/d/Y'),
| dataIndex: 'lastChange'
| },
| {
| menuDisabled: true,
| sortable: false,
| xtype: 'actioncolumn',
| width: 50,
| items: [{
| iconCls: 'sell-col',
| tooltip: 'Sell stock',
| handler: function(grid, rowIndex, colIndex) {
| var rec = grid.getStore().getAt(rowIndex);
| Ext.Msg.alert('Sell', 'Sell ' + rec.get('company'));
| }
| }, {
| getClass: function(v, meta, rec) {
| if (rec.get('change') < 0) {
| return 'alert-col';
| } else {
| return 'buy-col';
| }
| },
| getTip: function(v, meta, rec) {
| if (rec.get('change') < 0) {
| return 'Hold stock';
| } else {
| return 'Buy stock';
| }
| },
| handler: function(grid, rowIndex, colIndex) {
| var rec = grid.getStore().getAt(rowIndex),
| action = (rec.get('change') < 0 ? 'Hold' : 'Buy');
|
| Ext.Msg.alert(action, action + ' ' + rec.get('company'));
| }
| }]
| }
| ];
|
| this.callParent();
| }
| });
|
|