PageRenderTime 31ms CodeModel.GetById 23ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/ext-4.1.0_b3/src/grid/column/Boolean.js

https://bitbucket.org/srogerf/javascript
JavaScript | 82 lines | 17 code | 5 blank | 60 comment | 3 complexity | 39b95b2cd042ce8b4a4bdb7a92583906 MD5 | raw file
 1/**
 2 * A Column definition class which renders boolean data fields.  See the {@link Ext.grid.column.Column#xtype xtype}
 3 * config option of {@link Ext.grid.column.Column} for more details.
 4 *
 5 *     @example
 6 *     Ext.create('Ext.data.Store', {
 7 *        storeId:'sampleStore',
 8 *        fields:[
 9 *            {name: 'framework', type: 'string'},
10 *            {name: 'rocks', type: 'boolean'}
11 *        ],
12 *        data:{'items':[
13 *            { 'framework': "Ext JS 4",     'rocks': true  },
14 *            { 'framework': "Sencha Touch", 'rocks': true  },
15 *            { 'framework': "Ext GWT",      'rocks': true  }, 
16 *            { 'framework': "Other Guys",   'rocks': false } 
17 *        ]},
18 *        proxy: {
19 *            type: 'memory',
20 *            reader: {
21 *                type: 'json',
22 *                root: 'items'
23 *            }
24 *        }
25 *     });
26 *     
27 *     Ext.create('Ext.grid.Panel', {
28 *         title: 'Boolean Column Demo',
29 *         store: Ext.data.StoreManager.lookup('sampleStore'),
30 *         columns: [
31 *             { text: 'Framework',  dataIndex: 'framework', flex: 1 },
32 *             {
33 *                 xtype: 'booleancolumn', 
34 *                 text: 'Rocks',
35 *                 trueText: 'Yes',
36 *                 falseText: 'No', 
37 *                 dataIndex: 'rocks'
38 *             }
39 *         ],
40 *         height: 200,
41 *         width: 400,
42 *         renderTo: Ext.getBody()
43 *     });
44 */
45Ext.define('Ext.grid.column.Boolean', {
46    extend: 'Ext.grid.column.Column',
47    alias: ['widget.booleancolumn'],
48    alternateClassName: 'Ext.grid.BooleanColumn',
49
50    /**
51     * @cfg {String} trueText
52     * The string returned by the renderer when the column value is not falsey.
53     */
54    //<locale>
55    trueText: 'true',
56    //</locale>
57
58    /**
59     * @cfg {String} falseText
60     * The string returned by the renderer when the column value is falsey (but not undefined).
61     */
62    //<locale>
63    falseText: 'false',
64    //</locale>
65
66    /**
67     * @cfg {String} undefinedText
68     * The string returned by the renderer when the column value is undefined.
69     */
70    undefinedText: '&#160;',
71    
72    defaultRenderer: function(value){
73        if (value === undefined) {
74            return this.undefinedText;
75        }
76        
77        if (!value || value === 'false') {
78            return this.falseText;
79        }
80        return this.trueText;
81    }
82});