Print Friendly

# Class YAHOO.ext.grid.DefaultColumnModel

Package: | YAHOO.ext.grid
Class: | DefaultColumnModel
Extends: | AbstractColumnModel
Defined In: | DefaultColumnModel.js

This is the default implementation of a ColumnModel used by the Grid. It defines the columns in the grid.
Usage:

     var sort = YAHOO.ext.grid.DefaultColumnModel.sortTypes;
     var myColumns = [
    	{header: "Ticker", width: 60, sortable: true, sortType: sort.asUCString},
    	{header: "Company Name", width: 150, sortable: true, sortType: sort.asUCString},
    	{header: "Market Cap.", width: 100, sortable: true, sortType: sort.asFloat},
    	{header: "$ Sales", width: 100, sortable: true, sortType: sort.asFloat, renderer: money},
    	{header: "Employees", width: 100, sortable: true, sortType: sort.asFloat}
     ];
     var colModel = new YAHOO.ext.grid.DefaultColumnModel(myColumns);

## Public Properties

Property | Defined By
--- | ---
| config : Object | DefaultColumnModel
The config passed into the constructor
| defaultSortable : Boolean | DefaultColumnModel
Default sortable of columns which have no sortable specified (defaults to false)
| defaultWidth : Number | DefaultColumnModel
The width of columns which have no width specified (defaults to 100)
| sortTypes<static> : Object | DefaultColumnModel
<static> Defines the default sorting (casting?) comparison functions used when sorting data: sortTy...

## Public Methods

Method | Defined By
--- | ---
| DefaultColumnModel(`Object config`) | DefaultColumnModel
| addListener(`String eventName`, `Function handler`, [`Object scope`], [`boolean override`]) : void | Observable
Appends an event handler to this element
| delayedListener(`String eventName`, `Function handler`, [`Object scope`], [`Number delay`]) : Function | Observable
Appends an event handler to this element that is delayed the specified number of milliseconds.
| fireEvent(`String eventName`, `Object... args`) : Boolean | Observable
Fires the specified event with the passed parameters (minus the event name).
| getCellEditor(`Number colIndex`, `Number rowIndex`) : Object | DefaultColumnModel
Returns the editor defined for the cell/column.
| getColumnCount() : Number | DefaultColumnModel
Returns the number of columns.
| getColumnHeader(`Number col`) : String | DefaultColumnModel
Returns the header for the specified column.
| getColumnWidth(`Number col`) : Number | DefaultColumnModel
Returns the width for the specified column.
| getDataIndex(`Number col`) : Number | DefaultColumnModel
Returns the dataIndex for the specified column.
| getRenderer(`Number col`) : Function | DefaultColumnModel
Returns the rendering (formatting) function defined for the column.
| getSortType(`Number col`) : Function | DefaultColumnModel
Returns the sorting comparison function defined for the column (defaults to sortTypes.none).
| getTotalWidth(`Boolean includeHidden`) : Number | DefaultColumnModel
Returns the total width of all columns.
| isCellEditable(`Number colIndex`, `Number rowIndex`) : Boolean | DefaultColumnModel
Returns true if the cell is editable.
| isFixed() : void | DefaultColumnModel
Returns true if the column width cannot be changed
| isHidden(`Number colIndex`) : Boolean | DefaultColumnModel
Returns true if the column is hidden.
| isResizable() : void | DefaultColumnModel
Returns true if the column cannot be resized
| isSortable(`Number col`) : Boolean | DefaultColumnModel
Returns true if the specified column is sortable.
| purgeListeners() : void | Observable
Removes all listeners for this object
| removeListener(`String eventName`, `Function handler`, [`Object scope`]) : void | Observable
Removes a listener
| setColumnHeader(`Number col`, `String header`) : void | DefaultColumnModel
Sets the header for a column.
| setColumnWidth(`Number col`, `Number width`) : void | DefaultColumnModel
Sets the width for a column.
| setDataIndex(`Number col`, `Number dataIndex`) : void | DefaultColumnModel
Sets the dataIndex for a column.
| setEditable(`Number col`, `Boolean editable`) : void | DefaultColumnModel
Sets if a column is editable.
| setEditor(`Number col`, `Object editor`) : void | DefaultColumnModel
Sets the editor for a column.
| setHidden(`Number colIndex`) : void | DefaultColumnModel
Sets if a column is hidden.
| setRenderer(`Number col`, `Function fn`) : void | DefaultColumnModel
Sets the rendering (formatting) function for a column.
| setSortType(`Number col`, `Function fn`) : void | DefaultColumnModel
Sets the sorting comparison function for a column.

## Public Events

Event | Defined By
--- | ---
| headerchange : (`ColumnModel this`, `Number columnIndex`, `Number newText`) | AbstractColumnModel
Fires when the text of a header changes
| hiddenchange : (`ColumnModel this`, `Number columnIndex`, `Number hidden`) | AbstractColumnModel
Fires when a column is hidden or "unhidden"
| widthchange : (`ColumnModel this`, `Number columnIndex`, `Number newWidth`) | AbstractColumnModel
Fires when the width of a column changes

## Property Details

### config

`public Object config`
The config passed into the constructor
This property is defined by DefaultColumnModel.

### defaultSortable

`public Boolean defaultSortable`
Default sortable of columns which have no sortable specified (defaults to false)
This property is defined by DefaultColumnModel.

### defaultWidth

`public Number defaultWidth`
The width of columns which have no width specified (defaults to 100)
This property is defined by DefaultColumnModel.

### sortTypes<static>

`public Object sortTypes<static>`
<static> Defines the default sorting (casting?) comparison functions used when sorting data:
sortTypes.none - sorts data as it is without casting or parsing (the default)
sortTypes.asUCString - case insensitive string
sortTypes.asDate - attempts to parse data as a date
sortTypes.asFloat
sortTypes.asInt
This property is defined by DefaultColumnModel.

## Constructor Details

### DefaultColumnModel

`public function DefaultColumnModel(`Object config`)`
Parameters:

- `config` : Object
  The config object

## Method Details

### addListener

`public function addListener(`String eventName`, `Function handler`, [`Object scope`], [`boolean override`])`
Appends an event handler to this element
Parameters:

- `eventName` : String
  The type of event to listen for
- `handler` : Function
  The method the event invokes
- `scope` : Object
  (optional) The scope (this object) for the handler
- `override` : boolean
  (optional) If true, scope becomes the scope

Returns:

- `void`

This method is defined by Observable.

### delayedListener

`public function delayedListener(`String eventName`, `Function handler`, [`Object scope`], [`Number delay`])`
Appends an event handler to this element that is delayed the specified number of milliseconds.
Parameters:

- `eventName` : String
  The type of event to listen for
- `handler` : Function
  The method the event invokes
- `scope` : Object
  (optional) The scope (this object) for the handler
- `delay` : Number
  (optional) The number of milliseconds to delay

Returns:

- `Function`
  The wrapped function that was created (can be used to remove the listener)

This method is defined by Observable.

### fireEvent

`public function fireEvent(`String eventName`, `Object... args`)`
Fires the specified event with the passed parameters (minus the event name).
Parameters:

- `eventName` : String
- `args` : Object...
  Variable number of parameters are passed to handlers

Returns:

- `Boolean`
  returns false if any of the handlers return false otherwise it returns true

This method is defined by Observable.

### getCellEditor

`public function getCellEditor(`Number colIndex`, `Number rowIndex`)`
Returns the editor defined for the cell/column.
Parameters:

- `colIndex` : Number
  The column index
- `rowIndex` : Number
  The row index

Returns:

- `Object`

This method is defined by DefaultColumnModel.

### getColumnCount

`public function getColumnCount()`
Returns the number of columns.
Parameters:

- None.

Returns:

- `Number`

This method is defined by DefaultColumnModel.

### getColumnHeader

`public function getColumnHeader(`Number col`)`
Returns the header for the specified column.
Parameters:

- `col` : Number
  The column index

Returns:

- `String`

This method is defined by DefaultColumnModel.

### getColumnWidth

`public function getColumnWidth(`Number col`)`
Returns the width for the specified column.
Parameters:

- `col` : Number
  The column index

Returns:

- `Number`

This method is defined by DefaultColumnModel.

### getDataIndex

`public function getDataIndex(`Number col`)`
Returns the dataIndex for the specified column.
Parameters:

- `col` : Number
  The column index

Returns:

- `Number`

This method is defined by DefaultColumnModel.

### getRenderer

`public function getRenderer(`Number col`)`
Returns the rendering (formatting) function defined for the column.
Parameters:

- `col` : Number
  The column index

Returns:

- `Function`

This method is defined by DefaultColumnModel.

### getSortType

`public function getSortType(`Number col`)`
Returns the sorting comparison function defined for the column (defaults to sortTypes.none).
Parameters:

- `col` : Number
  The column index

Returns:

- `Function`

This method is defined by DefaultColumnModel.

### getTotalWidth

`public function getTotalWidth(`Boolean includeHidden`)`
Returns the total width of all columns.
Parameters:

- `includeHidden` : Boolean
  True to include hidden column widths

Returns:

- `Number`

This method is defined by DefaultColumnModel.

### isCellEditable

`public function isCellEditable(`Number colIndex`, `Number rowIndex`)`
Returns true if the cell is editable.
Parameters:

- `colIndex` : Number
  The column index
- `rowIndex` : Number
  The row index

Returns:

- `Boolean`

This method is defined by DefaultColumnModel.

### isFixed

`public function isFixed()`
Returns true if the column width cannot be changed
Parameters:

- None.

Returns:

- `void`

This method is defined by DefaultColumnModel.

### isHidden

`public function isHidden(`Number colIndex`)`
Returns true if the column is hidden.
Parameters:

- `colIndex` : Number
  The column index

Returns:

- `Boolean`

This method is defined by DefaultColumnModel.

### isResizable

`public function isResizable()`
Returns true if the column cannot be resized
Parameters:

- None.

Returns:

- `void`

This method is defined by DefaultColumnModel.

### isSortable

`public function isSortable(`Number col`)`
Returns true if the specified column is sortable.
Parameters:

- `col` : Number
  The column index

Returns:

- `Boolean`

This method is defined by DefaultColumnModel.

### purgeListeners

`public function purgeListeners()`
Removes all listeners for this object
Parameters:

- None.

Returns:

- `void`

This method is defined by Observable.

### removeListener

`public function removeListener(`String eventName`, `Function handler`, [`Object scope`])`
Removes a listener
Parameters:

- `eventName` : String
  The type of event to listen for
- `handler` : Function
  The handler to remove
- `scope` : Object
  (optional) The scope (this object) for the handler

Returns:

- `void`

This method is defined by Observable.

### setColumnHeader

`public function setColumnHeader(`Number col`, `String header`)`
Sets the header for a column.
Parameters:

- `col` : Number
  The column index
- `header` : String
  The new header

Returns:

- `void`

This method is defined by DefaultColumnModel.

### setColumnWidth

`public function setColumnWidth(`Number col`, `Number width`)`
Sets the width for a column.
Parameters:

- `col` : Number
  The column index
- `width` : Number
  The new width

Returns:

- `void`

This method is defined by DefaultColumnModel.

### setDataIndex

`public function setDataIndex(`Number col`, `Number dataIndex`)`
Sets the dataIndex for a column.
Parameters:

- `col` : Number
  The column index
- `dataIndex` : Number
  The new dataIndex

Returns:

- `void`

This method is defined by DefaultColumnModel.

### setEditable

`public function setEditable(`Number col`, `Boolean editable`)`
Sets if a column is editable.
Parameters:

- `col` : Number
  The column index
- `editable` : Boolean
  True if the column is editable

Returns:

- `void`

This method is defined by DefaultColumnModel.

### setEditor

`public function setEditor(`Number col`, `Object editor`)`
Sets the editor for a column.
Parameters:

- `col` : Number
  The column index
- `editor` : Object
  The editor object

Returns:

- `void`

This method is defined by DefaultColumnModel.

### setHidden

`public function setHidden(`Number colIndex`)`
Sets if a column is hidden.
Parameters:

- `colIndex` : Number
  The column index

Returns:

- `void`

This method is defined by DefaultColumnModel.

### setRenderer

`public function setRenderer(`Number col`, `Function fn`)`
Sets the rendering (formatting) function for a column.
Parameters:

- `col` : Number
  The column index
- `fn` : Function

Returns:

- `void`

This method is defined by DefaultColumnModel.

### setSortType

`public function setSortType(`Number col`, `Function fn`)`
Sets the sorting comparison function for a column.
Parameters:

- `col` : Number
  The column index
- `fn` : Function

Returns:

- `void`

This method is defined by DefaultColumnModel.

## Event Details

### headerchange

`public event headerchange`
Fires when the text of a header changes
Subscribers will be called with the following parameters:

- `this` : ColumnModel
- `columnIndex` : Number
  The column index
- `newText` : Number
  The new header text

This event is defined by AbstractColumnModel.

### hiddenchange

`public event hiddenchange`
Fires when a column is hidden or "unhidden"
Subscribers will be called with the following parameters:

- `this` : ColumnModel
- `columnIndex` : Number
  The column index
- `hidden` : Number
  true if hidden, false otherwise

This event is defined by AbstractColumnModel.

### widthchange

`public event widthchange`
Fires when the width of a column changes
Subscribers will be called with the following parameters:

- `this` : ColumnModel
- `columnIndex` : Number
  The column index
- `newWidth` : Number
  The new width

This event is defined by AbstractColumnModel.

Copyright © 2006 Jack Slocum. All rights reserved.