Observable ColumnModel
Package: | Ext.grid |
Defined In: | ColumnModel.js |
Class: | ColumnModel |
Subclasses: | PropertyColumnModel |
Extends: | Observable |
After the data has been read into the client side cache (Store), the ColumnModel is used to configure how and what parts of that data will be displayed in the vertical slices (columns) of the grid. The Ext.grid.ColumnModel Class is the default implementation of a ColumnModel used by implentations of GridPanel.
Data is mapped into the store's records and then indexed into the ColumnModel using the dataIndex:
{data source} == mapping ==> {data store} == dataIndex ==> {ColumnModel}
Each Column in the grid's ColumnModel is configured with a dataIndex to specify how the data within each record in the store is indexed into the ColumnModel.
There are two ways to initialize the ColumnModel class:
Initialization Method 1: an Array
var colModel = new Ext.grid.ColumnModel([
{ header: "Ticker", width: 60, sortable: true},
{ header: "Company Name", width: 150, sortable: true, id: 'company'},
{ header: "Market Cap.", width: 100, sortable: true},
{ header: "$ Sales", width: 100, sortable: true, renderer: money},
{ header: "Employees", width: 100, sortable: true, resizable: false}
]);
The ColumnModel may be initialized with an Array of Ext.grid.Column column configuration objects to define the initial layout / display of the columns in the Grid. The order of each Ext.grid.Column column configuration object within the specified Array defines the initial order of the column display. A Column's display may be initially hidden using the hidden config property (and then shown using the column header menu). Field's that are not included in the ColumnModel will not be displayable at all.
How each column in the grid correlates (maps) to the Ext.data.Record field in the Store the column draws its data from is configured through the dataIndex. If the dataIndex is not explicitly defined (as shown in the example above) it will use the column configuration's index in the Array as the index.
See Ext.grid.Column for additional configuration options for each column.
Initialization Method 2: an Object
In order to use configuration options from Ext.grid.ColumnModel, an Object may be used to initialize the ColumnModel. The column configuration Array will be specified in the columns config property. The defaults config property can be used to apply defaults for all columns, e.g.:
var colModel = new Ext.grid.ColumnModel({
columns: [
{ header: "Ticker", width: 60, menuDisabled: false},
{ header: "Company Name", width: 150, id: 'company'},
{ header: "Market Cap."},
{ header: "$ Sales", renderer: money},
{ header: "Employees", resizable: false}
],
defaults: {
sortable: true,
menuDisabled: true,
width: 100
},
listeners: {
hiddenchange: function(cm, colIndex, hidden) {
saveConfig(colIndex, hidden);
}
}
});
In both examples above, the ability to apply a CSS class to all cells in a column (including the header) is demonstrated through the use of the id config option. This column could be styled by including the following css:
//add this css *after* the core css is loaded
.x-grid3-td-company {
color: red; // entire column will have red font
}
// modify the header row only, adding an icon to the column header
.x-grid3-hd-company {
background: transparent
url(../../resources/images/icons/silk/building.png)
no-repeat 3px 3px ! important;
padding-left:20px;
}
Note that the "Company Name" column could be specified as the
Ext.grid.GridPanel.autoExpandColumn.Config Options | Defined By | |
---|---|---|
columns : Array An Array of object literals. The config options defined by
Ext.grid.Column are the options which may appear in the o... An Array of object literals. The config options defined by
Ext.grid.Column are the options which may appear in the object literal for each
individual column definition. | ColumnModel | |
defaultSortable : Boolean Default sortable of columns which have no
sortable specified (defaults to false). This property shall preferably be ... Default sortable of columns which have no
sortable specified (defaults to false). This property shall preferably be configured
through the defaults config property. | ColumnModel | |
defaultWidth : Number | ColumnModel | |
defaults : Object Object literal which will be used to apply Ext.grid.Column
configuration options to all columns. Configuration optio... Object literal which will be used to apply Ext.grid.Column
configuration options to all columns. Configuration options specified with
individual column configs will supersede these defaults. | ColumnModel | |
listeners : Object A config object containing one or more event handlers to be added to this
object during initialization. This should ... A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once. DOM events from ExtJs Components While some ExtJs Component classes export selected DOM events (e.g. "click", "mouseover" etc), this
is usually only done when extra value can be added. For example the DataView's
| Observable |
Property | Defined By | |
---|---|---|
config : Array An Array of Column definition objects representing the configuration
of this ColumnModel. See Ext.grid.Column for th... An Array of Column definition objects representing the configuration
of this ColumnModel. See Ext.grid.Column for the configuration properties that may
be specified. | ColumnModel |
Method | Defined By | |
---|---|---|
ColumnModel( Mixed config )
Parameters:
| ColumnModel | |
addEvents( Object object )
:
voidUsed to define events on this Observable Used to define events on this Observable Parameters:
| Observable | |
addListener( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object. Appends an event handler to this object. Parameters:
| Observable | |
destroy()
:
void Destroys this column model by purging any event listeners, and removing any editors. Destroys this column model by purging any event listeners, and removing any editors. Parameters:
| ColumnModel | |
enableBubble( Object events )
:
voidUsed to enable bubbling of events Used to enable bubbling of events Parameters:
| Observable | |
findColumnIndex( String col )
:
NumberFinds the index of the first matching column for the given dataIndex. Finds the index of the first matching column for the given dataIndex. Parameters:
| ColumnModel | |
fireEvent( String eventName , Object... args )
:
BooleanFires the specified event with the passed parameters (minus the event name).
An event may be set to bubble up an Obse... Fires the specified event with the passed parameters (minus the event name). An event may be set to bubble up an Observable parent hierarchy (See Ext.Component.getBubbleTarget) by calling enableBubble. Parameters:
| Observable | |
getCellEditor( Number colIndex , Number rowIndex )
:
Ext.EditorReturns the editor defined for the cell/column. Returns the editor defined for the cell/column. Parameters:
| ColumnModel | |
getColumnById( String id )
:
ObjectReturns the column for a specified id. Returns the column for a specified id. Parameters:
| ColumnModel | |
getColumnCount( Boolean visibleOnly )
:
NumberReturns the number of columns. Returns the number of columns. Parameters:
| ColumnModel | |
getColumnHeader( Number col )
:
StringReturns the header for the specified column. Returns the header for the specified column. Parameters:
| ColumnModel | |
getColumnId( Number index )
:
StringReturns the id of the column at the specified index. Returns the id of the column at the specified index. Parameters:
| ColumnModel | |
getColumnTooltip( Number col )
:
StringReturns the tooltip for the specified column. Returns the tooltip for the specified column. Parameters:
| ColumnModel | |
getColumnWidth( Number col )
:
NumberReturns the width for the specified column. Returns the width for the specified column. Parameters:
| ColumnModel | |
getColumnsBy( Function fn , [Object scope ] )
:
ArrayReturns the column configs that return true by the passed function that is called
with (columnConfig, index)
// retur... Returns the column configs that return true by the passed function that is called
with (columnConfig, index)
Parameters:
| ColumnModel | |
getDataIndex( Number col )
:
StringReturns the dataIndex for the specified column.
// Get field name for the column
var fieldName = grid.getColumnModel(... Returns the dataIndex for the specified column.
Parameters:
| ColumnModel | |
getIndexById( String id )
:
NumberReturns the index for a specified column id. Returns the index for a specified column id. Parameters:
| ColumnModel | |
getRenderer( Number col )
:
FunctionReturns the rendering (formatting) function defined for the column. Returns the rendering (formatting) function defined for the column. Parameters:
| ColumnModel | |
getTotalWidth( Boolean includeHidden )
:
NumberReturns the total width of all columns. Returns the total width of all columns. Parameters:
| ColumnModel | |
hasListener( String eventName )
:
BooleanChecks to see if this object has any listeners for a specified event Checks to see if this object has any listeners for a specified event Parameters:
| Observable | |
isCellEditable( Number colIndex , Number rowIndex )
:
BooleanReturns true if the cell is editable.
var store = new Ext.data.Store({...});
var colModel = new Ext.grid.ColumnModel(... Returns true if the cell is editable.
Parameters:
| ColumnModel | |
isFixed()
:
void Returns true if the column width cannot be changed Returns true if the column width cannot be changed Parameters:
| ColumnModel | |
isHidden( Number colIndex )
:
BooleanReturns true if the column is hidden. Returns true if the column is hidden. Parameters:
| ColumnModel | |
isMenuDisabled( Number col )
:
BooleanReturns true if the specified column menu is disabled. Returns true if the specified column menu is disabled. Parameters:
| ColumnModel | |
isResizable()
:
Boolean Returns true if the column can be resized Returns true if the column can be resized Parameters:
| ColumnModel | |
isSortable( Number col )
:
BooleanReturns true if the specified column is sortable. Returns true if the specified column is sortable. Parameters:
| ColumnModel | |
moveColumn( Number oldIndex , Number newIndex )
:
voidMoves a column from one position to another. Moves a column from one position to another. Parameters:
| ColumnModel | |
on( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object (shorthand for addListener.) Appends an event handler to this object (shorthand for addListener.) Parameters:
| Observable | |
purgeListeners()
:
void Removes all listeners for this object Removes all listeners for this object Parameters:
| Observable | |
relayEvents( Object o , Array events )
:
voidRelays selected events from the specified Observable as if the events were fired by this. Relays selected events from the specified Observable as if the events were fired by this. Parameters:
| Observable | |
removeListener( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler. Removes an event handler. Parameters:
| Observable | |
resumeEvents()
:
void Resume firing events. (see suspendEvents)
If events were suspended using the queueSuspended parameter, then all
event... Resume firing events. (see suspendEvents)
If events were suspended using the queueSuspended parameter, then all
events fired during event suspension will be sent to any listeners now. Parameters:
| Observable | |
setColumnHeader( Number col , String header )
:
voidSets the header for a column. Sets the header for a column. Parameters:
| ColumnModel | |
setColumnTooltip( Number col , String tooltip )
:
voidSets the tooltip for a column. Sets the tooltip for a column. Parameters:
| ColumnModel | |
setColumnWidth( Number col , Number width , Boolean suppressEvent )
:
voidSets the width for a column. Sets the width for a column. Parameters:
| ColumnModel | |
setConfig( Array config , Boolean initial )
:
voidReconfigures this column model according to the passed Array of column definition objects.
For a description of the i... Reconfigures this column model according to the passed Array of column definition objects. For a description of the individual properties of a column definition object, see the Config Options. Causes the configchange event to be fired. A GridPanel using this ColumnModel will listen for this event and refresh its UI automatically. Parameters:
| ColumnModel | |
setDataIndex( Number col , String dataIndex )
:
voidSets the dataIndex for a column. Sets the dataIndex for a column. Parameters:
| ColumnModel | |
setEditable( Number col , Boolean editable )
:
voidSets if a column is editable. Sets if a column is editable. Parameters:
| ColumnModel | |
setEditor( Number col , Object editor )
:
voidSets the editor for a column and destroys the prior editor. Sets the editor for a column and destroys the prior editor. Parameters:
| ColumnModel | |
setHidden( Number colIndex , Boolean hidden )
:
voidSets if a column is hidden.
myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column). Sets if a column is hidden.
Parameters:
| ColumnModel | |
setRenderer( Number col , Function fn )
:
voidSets the rendering (formatting) function for a column. See Ext.util.Format for some
default formatting functions. Sets the rendering (formatting) function for a column. See Ext.util.Format for some
default formatting functions. Parameters:
| ColumnModel | |
suspendEvents( Boolean queueSuspended )
:
voidSuspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters:
| Observable | |
un( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler (shorthand for removeListener.) Removes an event handler (shorthand for removeListener.) Parameters:
| Observable |
Event | Defined By | |
---|---|---|
columnmoved :
( ColumnModel this , Number oldIndex , Number newIndex )
Fires when a column is moved. Fires when a column is moved. Listeners will be called with the following arguments:
| ColumnModel | |
configchange :
( ColumnModel this )
Fires when the configuration is changed Fires when the configuration is changed Listeners will be called with the following arguments:
| ColumnModel | |
headerchange :
( ColumnModel this , Number columnIndex , String newText )
Fires when the text of a header changes. Fires when the text of a header changes. Listeners will be called with the following arguments:
| ColumnModel | |
hiddenchange :
( ColumnModel this , Number columnIndex , Boolean hidden )
Fires when a column is hidden or "unhidden". Fires when a column is hidden or "unhidden". Listeners will be called with the following arguments:
| ColumnModel | |
widthchange :
( ColumnModel this , Number columnIndex , Number newWidth )
Fires when the width of a column is programmaticially changed using
setColumnWidth.
Note internal resizing suppresses... Fires when the width of a column is programmaticially changed using
setColumnWidth .
Note internal resizing suppresses the event from firing. See also
Ext.grid.GridPanel.columnresize .Listeners will be called with the following arguments:
| ColumnModel |