Last active
September 14, 2015 10:30
-
-
Save aguimaraes/f894587593cd05fa7a9d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | |
| frame: true, | |
| title: 'Company data', | |
| bodyPadding: 5, | |
| layout: 'column', | |
| initComponent: function(){ | |
| Ext.apply(this, { | |
| width: 880, | |
| fieldDefaults: { | |
| labelAlign: 'left', | |
| labelWidth: 90, | |
| anchor: '100%', | |
| msgTarget: 'side' | |
| }, | |
| items: [{ | |
| columnWidth: 0.65, | |
| 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: 100, | |
| sortable: true, | |
| renderer: this.pctChangeRenderer, | |
| dataIndex: 'pctChange' | |
| }, { | |
| text: 'Last Updated', | |
| width: 115, | |
| sortable: true, | |
| renderer: Ext.util.Format.dateRenderer('m/d/Y'), | |
| dataIndex: 'lastChange' | |
| }, { | |
| text: 'Rating', | |
| width: 60, | |
| sortable: true, | |
| renderer: this.renderRating, | |
| dataIndex: 'rating' | |
| }], | |
| listeners: { | |
| scope: this, | |
| selectionchange: this.onSelectionChange | |
| } | |
| }, { | |
| columnWidth: 0.35, | |
| 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); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment