Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / grid / column / Date.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 passed date according to the default locale, or a configured
17  * {@link #format}.
18  *
19  *     @example
20  *     Ext.create('Ext.data.Store', {
21  *         storeId:'sampleStore',
22  *         fields:[
23  *             { name: 'symbol', type: 'string' },
24  *             { name: 'date',   type: 'date' },
25  *             { name: 'change', type: 'number' },
26  *             { name: 'volume', type: 'number' },
27  *             { name: 'topday', type: 'date' }                        
28  *         ],
29  *         data:[
30  *             { symbol: "msft",   date: '2011/04/22', change: 2.43, volume: 61606325, topday: '04/01/2010' },
31  *             { symbol: "goog",   date: '2011/04/22', change: 0.81, volume: 3053782,  topday: '04/11/2010' },
32  *             { symbol: "apple",  date: '2011/04/22', change: 1.35, volume: 24484858, topday: '04/28/2010' },            
33  *             { symbol: "sencha", date: '2011/04/22', change: 8.85, volume: 5556351,  topday: '04/22/2010' }            
34  *         ]
35  *     });
36  *     
37  *     Ext.create('Ext.grid.Panel', {
38  *         title: 'Date Column Demo',
39  *         store: Ext.data.StoreManager.lookup('sampleStore'),
40  *         columns: [
41  *             { text: 'Symbol',   dataIndex: 'symbol', flex: 1 },
42  *             { text: 'Date',     dataIndex: 'date',   xtype: 'datecolumn',   format:'Y-m-d' },
43  *             { text: 'Change',   dataIndex: 'change', xtype: 'numbercolumn', format:'0.00' },
44  *             { text: 'Volume',   dataIndex: 'volume', xtype: 'numbercolumn', format:'0,000' },
45  *             { text: 'Top Day',  dataIndex: 'topday', xtype: 'datecolumn',   format:'l' }            
46  *         ],
47  *         height: 200,
48  *         width: 450,
49  *         renderTo: Ext.getBody()
50  *     });
51  */
52 Ext.define('Ext.grid.column.Date', {
53     extend: 'Ext.grid.column.Column',
54     alias: ['widget.datecolumn'],
55     requires: ['Ext.Date'],
56     alternateClassName: 'Ext.grid.DateColumn',
57
58     /**
59      * @cfg {String} format
60      * A formatting string as used by {@link Ext.Date#format} to format a Date for this Column.
61      * This defaults to the default date from {@link Ext.Date#defaultFormat} which itself my be overridden
62      * in a locale file.
63      */
64
65     initComponent: function(){
66         var me = this;
67         
68         me.callParent(arguments);
69         if (!me.format) {
70             me.format = Ext.Date.defaultFormat;
71         }
72         me.renderer = Ext.util.Format.dateRenderer(me.format);
73     }
74 });