/*
* Ext JS Library 2.2.1
* Copyright(c) 2006-2009, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.grid.ColumnModel
* @extends Ext.util.Observable
* This is the default implementation of a ColumnModel used by the Grid. This class is initialized
* with an Array of column config objects.
*
* An individual column's config object defines the header string, the {@link Ext.data.Record}
* field the column draws its data from, an optional rendering function to provide customized
* data formatting, and the ability to apply a CSS class to all cells in a column through its
* {@link #id} config option.
*
Usage:
var colModel = new Ext.grid.ColumnModel([
{ header: "Ticker", width: 60, sortable: true},
{ header: "Company Name", width: 150, sortable: true},
{ header: "Market Cap.", width: 100, sortable: true},
{ header: "$ Sales", width: 100, sortable: true, renderer: money},
{ header: "Employees", width: 100, sortable: true, resizable: false}
]);
*
* The config options defined by this class are options which may appear in each
* individual column definition. In order to use configuration options from the superclass,
* specify the column configuration Array in the columns config property. eg: 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 {@link #configchange} event to be fired. A {@link Ext.grid.GridPanel GridPanel} using
* this ColumnModel will listen for this event and refresh its UI automatically. The data value for the cell. An object in which you may set the following attributes: A CSS class name to add to the cell's TD element. An HTML attribute definition string to apply to the data container element within the table cell
* (e.g. 'style="color:red;"').
* @constructor
* @param {Object} config An Array of column config objects. See this class's
* config objects for details.
*/
Ext.grid.ColumnModel = function(config){
/**
* The width of columns which have no width specified (defaults to 100)
* @type Number
*/
this.defaultWidth = 100;
/**
* Default sortable of columns which have no sortable specified (defaults to false)
* @type Boolean
*/
this.defaultSortable = false;
/**
* The config passed into the constructor
* @property {Array} config
*/
if(config.columns){
Ext.apply(this, config);
this.setConfig(config.columns, true);
}else{
this.setConfig(config, true);
}
this.addEvents(
/**
* @event widthchange
* Fires when the width of a column changes.
* @param {ColumnModel} this
* @param {Number} columnIndex The column index
* @param {Number} newWidth The new width
*/
"widthchange",
/**
* @event headerchange
* Fires when the text of a header changes.
* @param {ColumnModel} this
* @param {Number} columnIndex The column index
* @param {String} newText The new header text
*/
"headerchange",
/**
* @event hiddenchange
* Fires when a column is hidden or "unhidden".
* @param {ColumnModel} this
* @param {Number} columnIndex The column index
* @param {Boolean} hidden true if hidden, false otherwise
*/
"hiddenchange",
/**
* @event columnmoved
* Fires when a column is moved.
* @param {ColumnModel} this
* @param {Number} oldIndex
* @param {Number} newIndex
*/
"columnmoved",
// deprecated - to be removed
"columnlockchange",
/**
* @event configchange
* Fires when the configuration is changed
* @param {ColumnModel} this
*/
"configchange"
);
Ext.grid.ColumnModel.superclass.constructor.call(this);
};
Ext.extend(Ext.grid.ColumnModel, Ext.util.Observable, {
/**
* @cfg {String} id (optional) Defaults to the column's initial ordinal position.
* A name which identifies this column. The id is used to create a CSS class name which
* is applied to all table cells (including headers) in that column. The class name
* takes the form of
var colModel = new Ext.grid.ColumnModel({
listeners: {
widthchange: function(cm, colIndex, width) {
saveConfig(colIndex, width);
}
},
columns: [
{ header: "Ticker", width: 60, sortable: true},
{ header: "Company Name", width: 150, sortable: true},
{ header: "Market Cap.", width: 100, sortable: true},
{ header: "$ Sales", width: 100, sortable: true, renderer: money},
{ header: "Employees", width: 100, sortable: true, resizable: false}
]
});
x-grid3-td-id
*
* Header cells will also recieve this class name, but will also have the class .x-grid3-hd.x-grid3-td-id
* The {@link Ext.grid.GridPanel#autoExpandColumn} grid config option references the column
* via this identifier.
*/
/**
* @cfg {String} header The header text to display in the Grid view.
*/
/**
* @cfg {String} dataIndex (optional) The name of the field in the grid's {@link Ext.data.Store}'s
* {@link Ext.data.Record} definition from which to draw the column's value. If not
* specified, the column's index is used as an index into the Record's data Array.
*/
/**
* @cfg {Number} width (optional) The initial width in pixels of the column. This is ignored if the
* Grid's {@link Ext.grid.GridView view} is configured with {@link Ext.grid.GridView#forceFit forceFit} true.
*/
/**
* @cfg {Boolean} sortable (optional) True if sorting is to be allowed on this column.
* Defaults to the value of the {@link #defaultSortable} property.
* Whether local/remote sorting is used is specified in {@link Ext.data.Store#remoteSort}.
*/
/**
* @cfg {Boolean} fixed (optional) True if the column width cannot be changed. Defaults to false.
*/
/**
* @cfg {Boolean} resizable (optional) False to disable column resizing. Defaults to true.
*/
/**
* @cfg {Boolean} menuDisabled (optional) True to disable the column menu. Defaults to false.
*/
/**
* @cfg {Boolean} hidden (optional) True to hide the column. Defaults to false.
*/
/**
* @cfg {String} tooltip (optional) A text string to use as the column header's tooltip. If Quicktips are enabled, this
* value will be used as the text of the quick tip, otherwise it will be set as the header's HTML title attribute.
* Defaults to ''.
*/
/**
* @cfg {Function} renderer (optional) A function used to generate HTML markup for a cell
* given the cell's data value. See {@link #setRenderer}. If not specified, the
* default renderer uses the raw data value.
*/
/**
* @cfg {String} align (optional) Set the CSS text-align property of the column. Defaults to undefined.
*/
/**
* @cfg {String} css (optional) Set custom CSS for all table cells in the column (excluding headers). Defaults to undefined.
*/
/**
* @cfg {Boolean} hideable (optional) Specify as false to prevent the user from hiding this column
* (defaults to true). To disallow column hiding globally for all columns in the grid, use
* {@link Ext.grid.GridPanel#enableColumnHide} instead.
*/
/**
* @cfg {Ext.form.Field} editor (optional) The {@link Ext.form.Field} to use when editing values in this column if
* editing is supported by the grid.
*/
/**
* Returns the id of the column at the specified index.
* @param {Number} index The column index
* @return {String} the id
*/
getColumnId : function(index){
return this.config[index].id;
},
/**
*
*
*
The {@link Ext.data.Record} from which the data was extracted.
Row index
Column index
The {@link Ext.data.Store} object from which the Record was extracted.