13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Ext.define('KitchenSink.view.form.FormGrid', {
    extend: 'Ext.form.Panel',
    
    requires: [
        'Ext.grid.*',
        'Ext.form.*',
        'Ext.layout.container.Column',
        'KitchenSink.model.Company'
    ],
    xtype: 'form-grid',
    
    //<example>
    exampleTitle: 'Dynamic Form interacting with an embedded Grid',
    exampleDescription: [
        '<p>',
            'This Form demonstrates the fact that by virtue of inheriting from the Ext <b><tt>Container</tt></b>',
            'class, an Ext.form.Panel can contain any Ext <b><tt>Component</tt></b>. This includes all the',
            'subclasses of Ext.Panel, including the GridPanel.',
        '</p>',
        '<p>',
            'The Grid demonstrates the use of creation of derived fields in a Record created using a custom',
            '<b><tt>convert</tt></b> function, and the use of column renderers.',
        '</p>',
        '<p>',
            'The Form demonstrates the use of radio buttons grouped by name being set by the value of the derived',
            'rating field.',
        '</p>'
    ].join(''),
    themes: {
        classic: {
            width: 750,
            gridWidth: 0.6,
            formWidth: 0.4,
            percentChangeColumnWidth: 75,
            lastUpdatedColumnWidth: 85,
            ratingColumnWidth: 30
        },
        neptune: {
            width: 880,
            gridWidth: 0.65,
            formWidth: 0.35,
            percentChangeColumnWidth: 100,
            lastUpdatedColumnWidth: 115,
            ratingColumnWidth: 60
        }
    },
    //</example>
    
    frame: true,
    title: 'Company data',
    bodyPadding: 5,
    layout: 'column',
    
    initComponent: function(){
        Ext.apply(this, {
            width: this.themeInfo.width,
            fieldDefaults: {
                labelAlign: 'left',
                labelWidth: 90,
                anchor: '100%',
                msgTarget: 'side'
            },
 
            items: [{
                columnWidth: this.themeInfo.gridWidth,
                xtype: 'gridpanel',
                store: new Ext.data.Store({
                    model: KitchenSink.model.Company,
                    proxy: {
                        type: 'memory',
                        reader: {
                            type: 'array'
                        }
                    },
                    data: KitchenSink.data.DataSets.company
                }),
                height: 400,
                columns: [{
                    text: 'Company',
                    flex: 1,
                    sortable: true,
                    dataIndex: 'company'
                }, {
                    text: 'Price',
                    width: 75,
                    sortable: true,
                    dataIndex: 'price'
                }, {
                    text: 'Change',
                    width: 80,
                    sortable: true,
                    renderer: this.changeRenderer,
                    dataIndex: 'change'
                }, {
                    text: '% Change',
                    width: this.themeInfo.percentChangeColumnWidth,
                    sortable: true,
                    renderer: this.pctChangeRenderer,
                    dataIndex: 'pctChange'
                }, {
                    text: 'Last Updated',
                    width: this.themeInfo.lastUpdatedColumnWidth,
                    sortable: true,
                    renderer: Ext.util.Format.dateRenderer('m/d/Y'),
                    dataIndex: 'lastChange'
                }, {
                    text: 'Rating',
                    width: this.themeInfo.ratingColumnWidth,
                    sortable: true,
                    renderer: this.renderRating,
                    dataIndex: 'rating'
                }],
                listeners: {
                    scope: this,
                    selectionchange: this.onSelectionChange
                }
            }, {
                columnWidth: this.themeInfo.formWidth,
                margin: '0 0 0 10',
                xtype: 'fieldset',
                title:'Company details',
                layout: 'anchor',
                defaultType: 'textfield',
                items: [{
                    fieldLabel: 'Name',
                    name: 'company'
                },{
                    fieldLabel: 'Price',
                    name: 'price'
                },{
                    fieldLabel: '% Change',
                    name: 'pctChange'
                },{
                    xtype: 'datefield',
                    fieldLabel: 'Last Updated',
                    name: 'lastChange'
                }, {
                    xtype: 'radiogroup',
                    fieldLabel: 'Rating',
                    columns: 3,
                    defaults: {
                        name: 'rating' //Each radio has the same name so the browser will make sure only one is checked at once
                    },
                    items: [{
                        inputValue: '0',
                        boxLabel: 'A'
                    }, {
                        inputValue: '1',
                        boxLabel: 'B'
                    }, {
                        inputValue: '2',
                        boxLabel: 'C'
                    }]
                }]
            }]
        });
        this.callParent();
    },
    
    changeRenderer: function(val) {
        if (val > 0) {
            return '<span style="color:green;">' + val + '</span>';
        } else if(val < 0) {
            return '<span style="color:red;">' + val + '</span>';
        }
        return val;
    },
    
    pctChangeRenderer: function(val){
        if (val > 0) {
            return '<span style="color:green;">' + val + '%</span>';
        } else if(val < 0) {
            return '<span style="color:red;">' + val + '%</span>';
        }
        return val;
    },
    
    renderRating: function(val){
        switch (val) {
            case 0:
                return 'A';
            case 1:
                return 'B';
            case 2:
                return 'C';
        }
    },
    
    onSelectionChange: function(model, records) {
        var rec = records[0];
        if (rec) {
            this.getForm().loadRecord(rec);
        }
    }
});