Home > JavaScript > Apply Defaults attribute to all grid columns

Apply Defaults attribute to all grid columns

In almost every object that has a list in the ExtJS 4 it is possible to extract common attributes in the defaults section. The following is an example of how to do a column Grid object.

The first example without using defaults attribute:

var mygrid = Ext.create('Ext.grid.Panel', {
    //... store config, other config...
    columns: [
        { 
            header: 'ID', 
            dataIndex: 'id',
            hidden:true,
            sortable:true,
            width:65
        },
        {
            header: 'Firma', 
            dataIndex: 'company_name', 
            hidden:false, 
            sortable:true, 
            width:100
        },
        { 
            header: 'Adresa', 
            dataIndex: 'company_address', 
            hidden:false, 
            sortable:true, 
            width:100 
        }
    ]
});

Now an example with defaults attribute:

var mygrid = Ext.create('Ext.grid.Panel', {
    //... store config, other config...
    columns: {
        items: [
            { 
                header: 'ID', 
                dataIndex: 'id', 
                width: 65, 
                hidden:true 
            },
            { 
                header: 'Firma', 
                dataIndex: 'company_name' 
            },
            { 
                header: 'Adresa', 
                dataIndex: 'company_address' 
            }
        ],
        defaults: { 
            hidden:false, 
            sortable:true, 
            width:100 
        }
    }
});
Categories: JavaScript Tags: ,
  1. No comments yet.
  1. No trackbacks yet.