ObservableColumnModel
| Package: | CQ.Ext.grid |
| Class: | ColumnModel |
| Subclasses: | PropertyColumnModel |
| Extends: | CQ.Ext.util.Observable |
| Clientlib: | cq.widgets |
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 CQ.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 CQ.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 CQ.Ext.grid.Column column configuration objects to define the initial layout / display of the columns in the Grid. The order of each CQ.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). Fields that are not included in the ColumnModel will not be displayable at all.
How each column in the grid correlates (maps) to the CQ.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 CQ.Ext.grid.Column for additional configuration options for each column.
Initialization Method 2: an Object
In order to use configuration options from CQ.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 CQ.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
CQ.Ext.grid.GridPanel.autoExpandColumn. | Config Options | Defined By | |
|---|---|---|
|
columns : Array An Array of object literals. The config options defined by CQ.Ext.grid.Column are the options which may appear in the...
An Array of object literals. The config options defined by CQ.Ext.grid.Column are the options which may appear in the object literal for each individual column definition.
|
ColumnModel | |
|
defaultSortable : Boolean (optional) Default sortable of columns which have no sortable specified (defaults to false). This property shall pref...
(optional) 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 | |
| Property | Defined By | |
|---|---|---|
|
config : Array An Array of Column definition objects representing the configuration
of this ColumnModel. See CQ.Ext.grid.Column for...
An Array of Column definition objects representing the configuration
of this ColumnModel. See CQ.Ext.grid.Column for the configuration properties that may
be specified.
|
ColumnModel | |
| Method | Defined By | |
|---|---|---|
ColumnModel( Mixed config )
Parameters:
|
ColumnModel | |
|
constructor() : void
Parameters:
|
ColumnModel | |
|
destroy() : void Destroys this column model by purging any event listeners. Destroys and dereferences all Columns.
Destroys this column model by purging any event listeners. Destroys and dereferences all Columns.
Parameters:
|
ColumnModel | |
enableBubble( String/Array events ) : void Enables events fired by this Observable to bubble up an owner hierarchy by calling
this.getBubbleTarget() if present....
Enables events fired by this Observable to bubble up an owner hierarchy by calling
This is commonly used by CQ.Ext.Components to bubble events to owner Containers. See CQ.Ext.Component.getBubbleTarget. The default implementation in CQ.Ext.Component returns the Component's immediate owner. But if a known target is required, this can be overridden to access the required target more quickly. Example:
Parameters:
|
Observable | |
findColumnIndex( String col ) : Number Finds 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 | |
getCellEditor( Number colIndex, Number rowIndex ) : CQ.Ext.Editor
|
ColumnModel | |
getColumnById( String id ) : Object Returns the column for a specified id.
Returns the column for a specified id.
Parameters:
|
ColumnModel | |
getColumnCount( Boolean visibleOnly ) : Number Returns the number of columns.
Returns the number of columns.
Parameters:
|
ColumnModel | |
getColumnHeader( Number col ) : String Returns the header for the specified column.
Returns the header for the specified column.
Parameters:
|
ColumnModel | |
getColumnId( Number index ) : String Returns the id of the column at the specified index.
Returns the id of the column at the specified index.
Parameters:
|
ColumnModel | |
getColumnTooltip( Number col ) : String Returns the tooltip for the specified column.
Returns the tooltip for the specified column.
Parameters:
|
ColumnModel | |
getColumnWidth( Number col ) : Number Returns the width for the specified column.
Returns the width for the specified column.
Parameters:
|
ColumnModel | |
getColumnsBy( Function fn, [Object scope] ) : Array Returns the column configs that return true by the passed function that is called
with (columnConfig, index)
// retu...
Returns the column configs that return true by the passed function that is called
with (columnConfig, index)
Parameters:
|
ColumnModel | |
getDataIndex( Number col ) : String Returns 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 ) : Number Returns the index for a specified column id.
Returns the index for a specified column id.
Parameters:
|
ColumnModel | |
getRenderer( Number col ) : Function Returns the rendering (formatting) function defined for the column.
Returns the rendering (formatting) function defined for the column.
Parameters:
|
ColumnModel | |
getTotalWidth( Boolean includeHidden ) : Number Returns the total width of all columns.
Returns the total width of all columns.
Parameters:
|
ColumnModel | |
isCellEditable( Number colIndex, Number rowIndex ) : Boolean Returns true if the cell is editable.
var store = new CQ.Ext.data.Store({...});
var colModel = new CQ.Ext.grid.Colum...
Returns true if the cell is editable.
Parameters:
|
ColumnModel | |
isFixed( Number colIndex ) : Boolean
|
ColumnModel | |
isHidden( Number colIndex ) : Boolean
|
ColumnModel | |
isMenuDisabled( Number col ) : Boolean Returns 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 ) : Boolean Returns true if the specified column is sortable.
Returns true if the specified column is sortable.
Parameters:
|
ColumnModel | |
moveColumn( Number oldIndex, Number newIndex ) : void Moves a column from one position to another.
Moves a column from one position to another.
Parameters:
|
ColumnModel | |
relayEvents( Object o, Array events ) : void Relays 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 | |
setColumnHeader( Number col, String header ) : void Sets the header for a column.
Sets the header for a column.
Parameters:
|
ColumnModel | |
setColumnTooltip( Number col, String tooltip ) : void Sets the tooltip for a column.
Sets the tooltip for a column.
Parameters:
|
ColumnModel | |
setColumnWidth( Number col, Number width, Boolean suppressEvent ) : void Sets the width for a column.
Sets the width for a column.
Parameters:
|
ColumnModel | |
setConfig( Array config, Boolean initial ) : void Reconfigures 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 ) : void Sets the dataIndex for a column.
Sets the dataIndex for a column.
Parameters:
|
ColumnModel | |
setEditable( Number col, Boolean editable ) : void Sets if a column is editable.
Sets if a column is editable.
Parameters:
|
ColumnModel | |
setEditor( Number col, Object editor ) : void Sets 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 ) : void Sets if a column is hidden.
Sets if a column is hidden.
Parameters:
|
ColumnModel | |
setRenderer( Number col, Function fn ) : void Sets the rendering (formatting) function for a column. See CQ.Ext.util.Format for some
default formatting functions.
Sets the rendering (formatting) function for a column. See CQ.Ext.util.Format for some
default formatting functions.
Parameters:
|
ColumnModel | |
| 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
CQ.Ext.grid.GridPanel.columnresize.
Listeners will be called with the following arguments:
|
ColumnModel | |