Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / grid / property / HeaderContainer.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  * @class Ext.grid.property.HeaderContainer
17  * @extends Ext.grid.header.Container
18  * A custom HeaderContainer for the {@link Ext.grid.property.Grid}.  Generally it should not need to be used directly.
19  */
20 Ext.define('Ext.grid.property.HeaderContainer', {
21
22     extend: 'Ext.grid.header.Container',
23
24     alternateClassName: 'Ext.grid.PropertyColumnModel',
25     
26     nameWidth: 115,
27
28     // private - strings used for locale support
29     nameText : 'Name',
30     valueText : 'Value',
31     dateFormat : 'm/j/Y',
32     trueText: 'true',
33     falseText: 'false',
34
35     // private
36     nameColumnCls: Ext.baseCSSPrefix + 'grid-property-name',
37
38     /**
39      * Creates new HeaderContainer.
40      * @param {Ext.grid.property.Grid} grid The grid this store will be bound to
41      * @param {Object} source The source data config object
42      */
43     constructor : function(grid, store) {
44         var me = this;
45         
46         me.grid = grid;
47         me.store = store;
48         me.callParent([{
49             items: [{
50                 header: me.nameText,
51                 width: grid.nameColumnWidth || me.nameWidth,
52                 sortable: true,
53                 dataIndex: grid.nameField,
54                 renderer: Ext.Function.bind(me.renderProp, me),
55                 itemId: grid.nameField,
56                 menuDisabled :true,
57                 tdCls: me.nameColumnCls
58             }, {
59                 header: me.valueText,
60                 renderer: Ext.Function.bind(me.renderCell, me),
61                 getEditor: Ext.Function.bind(me.getCellEditor, me),
62                 flex: 1,
63                 fixed: true,
64                 dataIndex: grid.valueField,
65                 itemId: grid.valueField,
66                 menuDisabled: true
67             }]
68         }]);
69     },
70     
71     getCellEditor: function(record){
72         return this.grid.getCellEditor(record, this);
73     },
74
75     // private
76     // Render a property name cell
77     renderProp : function(v) {
78         return this.getPropertyName(v);
79     },
80
81     // private
82     // Render a property value cell
83     renderCell : function(val, meta, rec) {
84         var me = this,
85             renderer = me.grid.customRenderers[rec.get(me.grid.nameField)],
86             result = val;
87
88         if (renderer) {
89             return renderer.apply(me, arguments);
90         }
91         if (Ext.isDate(val)) {
92             result = me.renderDate(val);
93         } else if (Ext.isBoolean(val)) {
94             result = me.renderBool(val);
95         }
96         return Ext.util.Format.htmlEncode(result);
97     },
98
99     // private
100     renderDate : Ext.util.Format.date,
101
102     // private
103     renderBool : function(bVal) {
104         return this[bVal ? 'trueText' : 'falseText'];
105     },
106
107     // private
108     // Renders custom property names instead of raw names if defined in the Grid
109     getPropertyName : function(name) {
110         var pn = this.grid.propertyNames;
111         return pn && pn[name] ? pn[name] : name;
112     }
113 });