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