Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / grid / column / Number.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * A Column definition class which renders a numeric data field according to a {@link #format} string.
17  *
18  *     @example
19  *     Ext.create('Ext.data.Store', {
20  *        storeId:'sampleStore',
21  *        fields:[
22  *            { name: 'symbol', type: 'string' },
23  *            { name: 'price',  type: 'number' },
24  *            { name: 'change', type: 'number' },
25  *            { name: 'volume', type: 'number' },            
26  *        ],
27  *        data:[
28  *            { symbol: "msft",   price: 25.76,  change: 2.43, volume: 61606325 },
29  *            { symbol: "goog",   price: 525.73, change: 0.81, volume: 3053782  },
30  *            { symbol: "apple",  price: 342.41, change: 1.35, volume: 24484858 },            
31  *            { symbol: "sencha", price: 142.08, change: 8.85, volume: 5556351  }            
32  *        ]
33  *     });
34  *     
35  *     Ext.create('Ext.grid.Panel', {
36  *         title: 'Number Column Demo',
37  *         store: Ext.data.StoreManager.lookup('sampleStore'),
38  *         columns: [
39  *             { text: 'Symbol',         dataIndex: 'symbol', flex: 1 },
40  *             { text: 'Current Price',  dataIndex: 'price',  renderer: Ext.util.Format.usMoney },
41  *             { text: 'Change',         dataIndex: 'change', xtype: 'numbercolumn', format:'0.00' },
42  *             { text: 'Volume',         dataIndex: 'volume', xtype: 'numbercolumn', format:'0,000' }
43  *         ],
44  *         height: 200,
45  *         width: 400,
46  *         renderTo: Ext.getBody()
47  *     });
48  */
49 Ext.define('Ext.grid.column.Number', {
50     extend: 'Ext.grid.column.Column',
51     alias: ['widget.numbercolumn'],
52     requires: ['Ext.util.Format'],
53     alternateClassName: 'Ext.grid.NumberColumn',
54
55     /**
56      * @cfg {String} format
57      * A formatting string as used by {@link Ext.util.Format#number} to format a numeric value for this Column.
58      */
59     format : '0,000.00',
60
61     constructor: function(cfg) {
62         this.callParent(arguments);
63         this.renderer = Ext.util.Format.numberRenderer(this.format);
64     }
65 });