View Full Version : [ HOW-TO ] Declare defaults column type or renderer in a grid

3 Jun 2013, 5:28 AM

I would like to declare a grid with a default column/renderer type in order not to set it foreach column.
Is there a way to do that ?



3 Jun 2013, 1:31 PM
Yeah. Don't use the shorthand array syntax for the grid's columns config item, but treat it as a full fledged config for the header container.

Ext.create('Ext.grid.Panel', {
title: 'Important Dates',
store: Ext.data.StoreManager.lookup('dateStore'),
columns: {
defaults: {
renderer: Ext.util.Format.dateRenderer('n/j/Y'),
xtype: 'datecolumn'
items: [
{ text: 'Name', dataIndex: 'name', xtype: 'gridcolumn', renderer: Ext.String.capitalize },
{ text: 'Born', dataIndex: 'born' },
{ text: 'Graduated HS', dataIndex: 'hs_grad' },
{ text: 'Married', dataIndex: 'married' },
{ text: 'Died', dataIndex: 'died' }

You can also use this to set listeners for header-specific events like sortchange, menucreate, headertriggerclick, etc.