Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / grid / column / Boolean.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.column.Boolean
17  * @extends Ext.grid.column.Column
18  * <p>A Column definition class which renders boolean data fields.  See the {@link Ext.grid.column.Column#xtype xtype}
19  * config option of {@link Ext.grid.column.Column} for more details.</p>
20  *
21  * {@img Ext.grid.column.Boolean/Ext.grid.column.Boolean.png Ext.grid.column.Boolean grid column}
22  *
23  * ## Code
24  *     Ext.create('Ext.data.Store', {
25  *        storeId:'sampleStore',
26  *        fields:[
27  *            {name: 'framework', type: 'string'},
28  *            {name: 'rocks', type: 'boolean'}
29  *        ],
30  *        data:{'items':[
31  *            {"framework":"Ext JS 4", "rocks":true},
32  *            {"framework":"Sencha Touch", "rocks":true},
33  *            {"framework":"Ext GWT", "rocks":true},            
34  *            {"framework":"Other Guys", "rocks":false}            
35  *        ]},
36  *        proxy: {
37  *            type: 'memory',
38  *            reader: {
39  *                type: 'json',
40  *                root: 'items'
41  *            }
42  *        }
43  *     });
44  *     
45  *     Ext.create('Ext.grid.Panel', {
46  *         title: 'Boolean Column Demo',
47  *         store: Ext.data.StoreManager.lookup('sampleStore'),
48  *         columns: [
49  *             {text: 'Framework',  dataIndex: 'framework', flex: 1},
50  *             {
51  *                 xtype: 'booleancolumn', 
52  *                 text: 'Rocks',
53  *                 trueText: 'Yes',
54  *                 falseText: 'No', 
55  *                 dataIndex: 'rocks'}
56  *         ],
57  *         height: 200,
58  *         width: 400,
59  *         renderTo: Ext.getBody()
60  *     });
61  */
62 Ext.define('Ext.grid.column.Boolean', {
63     extend: 'Ext.grid.column.Column',
64     alias: ['widget.booleancolumn'],
65     alternateClassName: 'Ext.grid.BooleanColumn',
66
67     /**
68      * @cfg {String} trueText
69      * The string returned by the renderer when the column value is not falsey (defaults to <tt>'true'</tt>).
70      */
71     trueText: 'true',
72
73     /**
74      * @cfg {String} falseText
75      * The string returned by the renderer when the column value is falsey (but not undefined) (defaults to
76      * <tt>'false'</tt>).
77      */
78     falseText: 'false',
79
80     /**
81      * @cfg {String} undefinedText
82      * The string returned by the renderer when the column value is undefined (defaults to <tt>'&#160;'</tt>).
83      */
84     undefinedText: '&#160;',
85
86     constructor: function(cfg){
87         this.callParent(arguments);
88         var trueText      = this.trueText,
89             falseText     = this.falseText,
90             undefinedText = this.undefinedText;
91
92         this.renderer = function(value){
93             if(value === undefined){
94                 return undefinedText;
95             }
96             if(!value || value === 'false'){
97                 return falseText;
98             }
99             return trueText;
100         };
101     }
102 });