Print Friendly

Class YAHOO.ext.grid.DefaultDataModel

Package:YAHOO.ext.grid
Class:DefaultDataModel
Extends:AbstractDataModel
Subclasses:LoadableDataModel
Defined In:DefaultDataModel.js
This is the default implementation of a DataModel used by the Grid. It works with multi-dimensional array based data. Using the event system in the base class YAHOO.ext.grid.AbstractDataModel, all updates to this DataModel are automatically reflected in the user interface.
Usage:

var myData = [
	["MSFT","Microsoft Corporation", "314,571.156", "32,187.000", "55000"],
	["ORCL", "Oracle Corporation", "62,615.266", "9,519.000", "40650"]
];
var dataModel = new YAHOO.ext.grid.DefaultDataModel(myData);

Public Properties

Property Defined By
  addListener : Object AbstractDataModel
Inherited from Observable
  delayedListener : Object AbstractDataModel
Inherited from Observable
  fireEvent : Object AbstractDataModel
Inherited from Observable
  on : Object AbstractDataModel
Inherited from Observable
  onCellUpdated : YAHOO.util.CustomEvent AbstractDataModel
Deprecated. Fires when a cell is updated - fireDirect sig: (this, rowIndex, columnIndex)
  onRowsDeleted : YAHOO.util.CustomEvent AbstractDataModel
Deprecated. Fires when rows are deleted - fireDirect sig: (this, firstRowIndex, lastRowIndex)
  onRowsInserted : YAHOO.util.CustomEvent AbstractDataModel
Deprecated. Fires when a rows are inserted - fireDirect sig: (this, firstRowIndex, lastRowIndex)
  onRowsSorted : YAHOO.util.CustomEvent AbstractDataModel
Deprecated. Fires when a sort has reordered the rows - fireDirect sig: (this, sortColumnIndex, sortDirection = 'ASC'...
  onRowsUpdated : YAHOO.util.CustomEvent AbstractDataModel
Deprecated. Fires when a rows are updated - fireDirect sig: (this, firstRowIndex, lastRowIndex)
  onTableDataChanged : YAHOO.util.CustomEvent AbstractDataModel
Deprecated. Fires when all data needs to be revalidated - fireDirect sig: (thisd)
  removeListener : Object AbstractDataModel
Inherited from Observable

Public Methods

Method Defined By
  DefaultDataModel() DefaultDataModel
  addRow(Array cellValues) : Number DefaultDataModel
Adds a row to the dataset.
  applySort() : void DefaultDataModel
Applies the last used sort to the current data.
  each() : void DefaultDataModel
Calls passed function with each rows data - if the function returns false it stops.
  filter(Object query) : Number DefaultDataModel
Filter the DataModel rows by the query defined in spec, see query for more details on the query spec.
  fireCellUpdated() : void AbstractDataModel
Notifies listeners that the value of the cell at [row, col] has been updated
  fireRowsDeleted() : void AbstractDataModel
Notifies listeners that rows in the range [firstRow, lastRow], inclusive, have been deleted
  fireRowsInserted() : void AbstractDataModel
Notifies listeners that rows in the range [firstRow, lastRow], inclusive, have been inserted
  fireRowsSorted() : void AbstractDataModel
Notifies listeners that rows have been sorted and any indexes may be invalid
  fireRowsUpdated() : void AbstractDataModel
Notifies listeners that rows in the range [firstRow, lastRow], inclusive, have been updated
  fireTableDataChanged() : void AbstractDataModel
Notifies listeners that all data for the grid may have changed - use as a last resort. This also wipes out all selec...
  getRow() : Array DefaultDataModel
Returns the column data for the specified row.
  getRowCount() : Number DefaultDataModel
Returns the number of rows in the dataset
  getRowId() : Number DefaultDataModel
Returns the ID of the specified row. By default it return the value of the first column. Override to provide more ad...
  getRows(Array indexes) : Array DefaultDataModel
Returns the column data for the specified rows as a multi-dimensional array: rows[3][0] would give you the value of ...
  getSortState() : Object AbstractDataModel
Interface method to supply the view with info regarding the Grid's current sort state - if overridden, this should re...
  getTotalRowCount() : void AbstractDataModel
Empty interface method - Classes which extend AbstractDataModel should implement this method to support virtual row c...
  getValueAt(Number rowIndex, Number colIndex) : Object DefaultDataModel
Returns the value at the specified data position
  insertRow(Number index, Array cellValues) : Number DefaultDataModel
Inserts a row a the specified location in the dataset.
  query(Object spec, Boolean returnUnmatched) : Array DefaultDataModel
Query the DataModel rows by the filters defined in spec, for example... // column 1 starts with Jack, column 2 filte...
  removeRow(Number index) : void DefaultDataModel
Remove a row.
  setValueAt(Object value, Number rowIndex, Number colIndex) : void DefaultDataModel
Sets the specified value at the specified data position
  sort(Function/Object sortInfo, Number columnIndex, String direction) : void DefaultDataModel
Sorts the data by the specified column - Uses the sortType specified for the column in the passed columnModel.

Public Events

This class has no public events.

Property Details

addListener

public Object addListener
Inherited from Observable
This property is defined by AbstractDataModel.

delayedListener

public Object delayedListener
Inherited from Observable
This property is defined by AbstractDataModel.

fireEvent

public Object fireEvent
Inherited from Observable
This property is defined by AbstractDataModel.

on

public Object on
Inherited from Observable
This property is defined by AbstractDataModel.

onCellUpdated

public YAHOO.util.CustomEvent onCellUpdated
Deprecated. Fires when a cell is updated - fireDirect sig: (this, rowIndex, columnIndex)
This property is defined by AbstractDataModel.

onRowsDeleted

public YAHOO.util.CustomEvent onRowsDeleted
Deprecated. Fires when rows are deleted - fireDirect sig: (this, firstRowIndex, lastRowIndex)
This property is defined by AbstractDataModel.

onRowsInserted

public YAHOO.util.CustomEvent onRowsInserted
Deprecated. Fires when a rows are inserted - fireDirect sig: (this, firstRowIndex, lastRowIndex)
This property is defined by AbstractDataModel.

onRowsSorted

public YAHOO.util.CustomEvent onRowsSorted
Deprecated. Fires when a sort has reordered the rows - fireDirect sig: (this, sortColumnIndex, sortDirection = 'ASC' or 'DESC')
This property is defined by AbstractDataModel.

onRowsUpdated

public YAHOO.util.CustomEvent onRowsUpdated
Deprecated. Fires when a rows are updated - fireDirect sig: (this, firstRowIndex, lastRowIndex)
This property is defined by AbstractDataModel.

onTableDataChanged

public YAHOO.util.CustomEvent onTableDataChanged
Deprecated. Fires when all data needs to be revalidated - fireDirect sig: (thisd)
This property is defined by AbstractDataModel.

removeListener

public Object removeListener
Inherited from Observable
This property is defined by AbstractDataModel.

Constructor Details

DefaultDataModel

public function DefaultDataModel()
Parameters:
  • None.

Method Details

addRow

public function addRow(Array cellValues)
Adds a row to the dataset.
Parameters:
  • cellValues : Array
    The array of values for the new row
Returns:
  • Number
    The index of the added row
This method is defined by DefaultDataModel.

applySort

public function applySort()
Applies the last used sort to the current data.
Parameters:
  • None.
Returns:
  • void
This method is defined by DefaultDataModel.

each

public function each()
Calls passed function with each rows data - if the function returns false it stops.
Parameters:
  • None.
Returns:
  • void
This method is defined by DefaultDataModel.

filter

public function filter(Object query)
Filter the DataModel rows by the query defined in spec, see query for more details on the query spec.
Parameters:
  • query : Object
    The query spec query
Returns:
  • Number
    The number of rows removed
This method is defined by DefaultDataModel.

fireCellUpdated

public function fireCellUpdated()
Notifies listeners that the value of the cell at [row, col] has been updated
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

fireRowsDeleted

public function fireRowsDeleted()
Notifies listeners that rows in the range [firstRow, lastRow], inclusive, have been deleted
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

fireRowsInserted

public function fireRowsInserted()
Notifies listeners that rows in the range [firstRow, lastRow], inclusive, have been inserted
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

fireRowsSorted

public function fireRowsSorted()
Notifies listeners that rows have been sorted and any indexes may be invalid
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

fireRowsUpdated

public function fireRowsUpdated()
Notifies listeners that rows in the range [firstRow, lastRow], inclusive, have been updated
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

fireTableDataChanged

public function fireTableDataChanged()
Notifies listeners that all data for the grid may have changed - use as a last resort. This also wipes out all selections a user might have made.
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

getRow

public function getRow()
Returns the column data for the specified row.
Parameters:
  • None.
Returns:
  • Array
This method is defined by DefaultDataModel.

getRowCount

public function getRowCount()
Returns the number of rows in the dataset
Parameters:
  • None.
Returns:
  • Number
This method is defined by DefaultDataModel.

getRowId

public function getRowId()
Returns the ID of the specified row. By default it return the value of the first column. Override to provide more advanced ID handling.
Parameters:
  • None.
Returns:
  • Number
This method is defined by DefaultDataModel.

getRows

public function getRows(Array indexes)
Returns the column data for the specified rows as a multi-dimensional array: rows[3][0] would give you the value of row 4, column 0.
Parameters:
  • indexes : Array
    The row indexes to fetch
Returns:
  • Array
This method is defined by DefaultDataModel.

getSortState

public function getSortState()
Interface method to supply the view with info regarding the Grid's current sort state - if overridden, this should return an object like this {column: this.sortColumn, direction: this.sortDir}.
Parameters:
  • None.
Returns:
  • Object
This method is defined by AbstractDataModel.

getTotalRowCount

public function getTotalRowCount()
Empty interface method - Classes which extend AbstractDataModel should implement this method to support virtual row counts.
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

getValueAt

public function getValueAt(Number rowIndex, Number colIndex)
Returns the value at the specified data position
Parameters:
  • rowIndex : Number
  • colIndex : Number
Returns:
  • Object
This method is defined by DefaultDataModel.

insertRow

public function insertRow(Number index, Array cellValues)
Inserts a row a the specified location in the dataset.
Parameters:
  • index : Number
    The index where the row should be inserted
  • cellValues : Array
    The array of values for the new row
Returns:
  • Number
    The index the row was inserted in
This method is defined by DefaultDataModel.

query

public function query(Object spec, Boolean returnUnmatched)
Query the DataModel rows by the filters defined in spec, for example...

// column 1 starts with Jack, column 2 filtered by myFcn, column 3 equals 'Fred'
dataModel.filter({1: /^Jack.+/i}, 2: myFcn, 3: 'Fred'});
Parameters:
  • spec : Object
    The spec is generally an object literal consisting of column index and filter type. The filter type can be a string/number (exact match), a regular expression to test using String.search() or a function to call. If it's a function, it will be called with the value for the specified column and an array of the all column values for that row: yourFcn(value, columnData). If it returns anything other than true, the row is not a match. If you have modified Object.prototype this method may fail.
  • returnUnmatched : Boolean
    True to return rows which don't match the query instead of rows that do match
Returns:
  • Array
    An array of row indexes that match
This method is defined by DefaultDataModel.

removeRow

public function removeRow(Number index)
Remove a row.
Parameters:
  • index : Number
Returns:
  • void
This method is defined by DefaultDataModel.

setValueAt

public function setValueAt(Object value, Number rowIndex, Number colIndex)
Sets the specified value at the specified data position
Parameters:
  • value : Object
    The new value
  • rowIndex : Number
  • colIndex : Number
Returns:
  • void
This method is defined by DefaultDataModel.

sort

public function sort(Function/Object sortInfo, Number columnIndex, String direction)
Sorts the data by the specified column - Uses the sortType specified for the column in the passed columnModel.
Parameters:
  • sortInfo : Function/Object
    A sort comparison function or null to use the default or A object that has a method getSortType(index) that returns a function like a grid column model.
  • columnIndex : Number
    The column index to sort by
  • direction : String
    The direction of the sort ('DESC' or 'ASC')
Returns:
  • void
This method is defined by DefaultDataModel.

Copyright © 2006 Jack Slocum. All rights reserved.