EXTJS 4:在renderer中如何控制一個CheckColumn的行為,如顯示,只讀等屬性


在編寫grid下的column時,大家肯定會經常用到renderer這個方法來改變文字的呈現形式,那么如果該column是一個特殊的column,比如CheckColumn時,該方法應該怎樣寫呢?官方的文檔中並沒有對此多作說明,不過仔細研究后,發現原理是很類似的

給個例子,根據數據中的值,來決定是否顯示CheckColumn

var store = Ext.create('Ext.data.Store', {
    fields : ['name', 'email', 'phone', 'active','cancheck'],
    data   : {
        items : [
            { name : 'Lisa',  email : 'lisa@simpsons.com',  phone : '555-111-1224', active : true ,cancheck:true },
            { name : 'Bart',  email : 'bart@simpsons.com',  phone : '555-222-1234', active : true,cancheck:false  },
            { name : 'Homer', email : 'home@simpsons.com',  phone : '555-222-1244', active : false,cancheck:true },
            { name : 'Marge', email : 'marge@simpsons.com', phone : '555-222-1254', active : true ,cancheck:false }
        ]
    },
    proxy  : {
        type   : 'memory',
        reader : {
            type : 'json',
            root : 'items'
        }
    }
});

Ext.create('Ext.grid.Panel', {
    title    : 'Simpsons',
    height   : 200,
    width    : 400,
    renderTo : Ext.getBody(),
    store    : store,
    columns  : [
        { text : 'Name', dataIndex : 'name' },
        { text : 'Email', dataIndex : 'email', flex : 1 },
        { text : 'Phone', dataIndex : 'phone' },
        { xtype : 'checkcolumn', text : 'Active', dataIndex : 'active',
         renderer:function(val, m, rec) {            

        if (rec.get('cancheck') == false) return ''; else{ return (new Ext.grid.column.CheckColumn).renderer(val); } }} ] });

運行環境 extjs4.2.1 運行效果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM