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.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.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). Fields 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.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.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.
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.
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.
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.
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.
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
- col : String
The dataIndex to find
Returns
- Number The column index, or null if no match was found
Returns the editor defined for the cell/column.
Returns the editor defined for the cell/column.
Parameters
- colIndex : Number
The column index
- rowIndex : Number
The row index
Returns
- Ext.Editor The {@link Ext.Editor Editor} that was created to wrap
the {@link Ext.form.Field Field} used to edit the cell.
Returns the column at the specified index.
Returns the column at the specified index.
Parameters
- index : Number
The column index
Returns
Returns the column for a specified id.
Returns the column for a specified id.
Parameters
Returns
Returns the number of columns.
Returns the number of columns.
Parameters
Returns
Returns the header for the specified column.
Returns the header for the specified column.
Parameters
- col : Number
The column index
Returns
Returns the id of the column at the specified index.
Returns the id of the column at the specified index.
Parameters
- index : Number
The column index
Returns
Returns the width for the specified column.
Returns the width for the specified column.
Parameters
- col : Number
The column index
Returns
getColumnsBy(
Function fn, [Object scope] ) : Ext.util.MixedCollection
Returns 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)
// returns an array of column config objects for all hidden columns
var columns = grid.getColumnModel().getColumnsBy(function(c){
return c.hidden;
});
Parameters
Returns
- Ext.util.MixedCollection result
Returns the dataIndex for the specified column.
// Get field name for the column
var fieldName = grid.getColumnModel(...
Returns the dataIndex for the specified column.
// Get field name for the column
var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
Parameters
- col : Number
The column index
Returns
- String The column's dataIndex
Returns the index for a specified column id.
Returns the index for a specified column id.
Parameters
Returns
- Number the index, or -1 if not found
Returns the rendering (formatting) function defined for the column.
Returns the rendering (formatting) function defined for the column.
Parameters
- col : Number
The column index.
Returns
- Function The function used to render the cell. See {@link #setRenderer}.
Returns the total width of all columns.
Returns the total width of all columns.
Parameters
Returns
Returns true if the cell is editable.
var store = new Ext.data.Store({...});
var colModel = new Ext.ColumnModel({
c...
Returns true if the cell is editable.
var store = new Ext.data.Store({...});
var colModel = new Ext.ColumnModel({
columns: [...],
isCellEditable: function(col, row) {
var record = store.getAt(row);
if (record.get('readonly')) { // replace with your condition
return false;
}
return Ext.ColumnModel.prototype.isCellEditable.call(this, col, row);
}
});
var grid = new Ext.grid.GridPanel({
store: store,
colModel: colModel,
...
});
Parameters
- colIndex : Number
The column index
- rowIndex : Number
The row index
Returns
isFixed(
Number colIndex ) : Boolean
Returns true if the column is fixed,
false otherwise.
Returns
true if the column is
fixed
,
false otherwise.
Parameters
- colIndex : Number
The column index
Returns
Returns true if the column is hidden,
false otherwise.
Returns
true if the column is
hidden
,
false otherwise.
Parameters
- colIndex : Number
The column index
Returns
Returns true if the column can be resized
Returns true if the column can be resized
Returns true if the specified column is sortable.
Returns true if the specified column is sortable.
Parameters
- col : Number
The column index
Returns
moveColumn(
Number oldIndex, Number newIndex ) : Void
Moves a column from one position to another.
Moves a column from one position to another.
Parameters
Returns
Sets the header for a column.
Sets the header for a column.
Parameters
- col : Number
The column index
- header : String
The new header
Returns
setColumnWidth(
Number col, Number width, Boolean suppressEvent ) : Void
Sets the width for a column.
Sets the width for a column.
Parameters
- col : Number
The column index
- width : Number
The new width
- suppressEvent : Boolean
True to suppress firing the
widthchange
event. Defaults to false.
Returns
Sets the dataIndex for a column.
Sets the dataIndex for a column.
Parameters
- col : Number
The column index
- dataIndex : String
The new dataIndex
Returns
Sets if a column is editable.
Sets if a column is editable.
Parameters
Returns
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
- col : Number
The column index
- editor : Object
The editor object
Returns
setHidden(
Number colIndex, Boolean hidden ) : Void
Sets if a column is hidden.
myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column).
Sets if a column is hidden.
myGrid.getColumnModel().setHidden(0, true); // hide column 0 (0 = the first column).
Parameters
Returns
Sets 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
- col : Number
The column index
- fn : Function
The function to use to process the cell's raw data
to return HTML markup for the grid view. The render function is called with
the following parameters:
- value : Object
The data value for the cell.
- metadata : Object
An object in which you may set the following attributes:
- record : Ext.data.record
The Ext.data.Record from which the data was extracted.
- rowIndex : Number
Row index
- colIndex : Number
Column index
- store : Ext.data.Store
The Ext.data.Store object from which the Record was extracted.
Returns
columnmoved(
ColumnModel this, Number oldIndex, Number newIndex )
Fires when a column is moved.
Fires when a column is moved.
Parameters
- this : ColumnModel
- oldIndex : Number
- newIndex : Number
Returns
Fires when the configuration is changed
Fires when the configuration is changed
Parameters
Returns
hiddenchange(
ColumnModel this, Number columnIndex, Boolean hidden )
Fires when a column is hidden or "unhidden".
Fires when a column is hidden or "unhidden".
Parameters
Returns
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
.
Parameters
- this : ColumnModel
- columnIndex : Number
The column index
- newWidth : Number
The new width
Returns