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);
This class has no public properties.
|
DefaultDataModel(Array data ) |
DefaultDataModel |
|
|
addListener(String eventName , Function handler , [Object scope ], [boolean override ]) : void |
Observable |
Appends an event handler to this component |
|
addRow(Array cellValues ) : Number |
DefaultDataModel |
Adds a row to the dataset. |
|
applySort() : void |
DefaultDataModel |
Applies the last used sort to the current data. |
|
bufferedListener(String eventName , Function handler , [Object scope ], [Number millis ]) : Function |
Observable |
Appends an event handler to this component that is buffered. If the event is triggered more than once
in the specifie... |
|
delayedListener(String eventName , Function handler , [Object scope ], [Number delay ]) : Function |
Observable |
Appends an event handler to this component that is delayed the specified number of milliseconds. This
is useful for e... |
|
each(Function fn , [Object scope ]) : 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. |
|
fireEvent(String eventName , Object... args ) : Boolean |
Observable |
Fires the specified event with the passed parameters (minus the event name). |
|
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 info regarding the Grid's current sort state - if overridden,
this should return an object... |
|
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. |
|
on(String eventName , Function handler , [Object scope ], [boolean override ]) : void |
Observable |
Appends an event handler to this element (shorthand for addListener) |
|
purgeListeners() : void |
Observable |
Removes all listeners for this object |
|
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... |
|
removeListener(String eventName , Function handler , [Object scope ]) : void |
Observable |
Removes a listener |
|
removeRow(Number index ) : void |
DefaultDataModel |
Remove a row. |
|
setDefaultSort(Function/Object sortInfo , Number columnIndex , String direction ) : void |
DefaultDataModel |
Sets the default sort info. Note: this function does not actually apply the sort. |
|
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. |
addListener
public function addListener(String eventName
, Function handler
, [Object scope
], [boolean override
])
Appends an event handler to this component
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope (this object) for the handler
override
: boolean(optional) If true, scope becomes the scope
Returns:
addRow
public function addRow(Array cellValues
)
Adds a row to the dataset.
This method is defined by DefaultDataModel.
applySort
public function applySort()
Applies the last used sort to the current data.
This method is defined by DefaultDataModel.
bufferedListener
public function bufferedListener(String eventName
, Function handler
, [Object scope
], [Number millis
])
Appends an event handler to this component that is buffered. If the event is triggered more than once
in the specified time-frame, only the last one actually fires.
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope (this object) for the handler
millis
: Number(optional) The number of milliseconds to buffer (defaults to 250)
Returns:
delayedListener
public function delayedListener(String eventName
, Function handler
, [Object scope
], [Number delay
])
Appends an event handler to this component that is delayed the specified number of milliseconds. This
is useful for events that modify the DOM and need to wait for the browser to catch up.
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope (this object) for the handler
delay
: Number(optional) The number of milliseconds to delay (defaults to 1 millisecond)
Returns:
each
public function each(Function fn
, [Object scope
])
Calls passed function with each rows data - if the function returns false it stops.
Parameters:
fn
: Functionscope
: Object(optional)
Returns:
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.
This method is defined by DefaultDataModel.
fireEvent
public function fireEvent(String eventName
, Object... args
)
Fires the specified event with the passed parameters (minus the event name).
getRow
public function getRow()
Returns the column data for the specified row.
This method is defined by DefaultDataModel.
getRowCount
public function getRowCount()
Returns the number of rows in the dataset
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.
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
: ArrayThe row indexes to fetch
Returns:
This method is defined by DefaultDataModel.
getSortState
public function getSortState()
Interface method to supply info regarding the Grid's current sort state - if overridden,
this should return an object like this {column: this.sortColumn, direction: this.sortDir}.
getValueAt
public function getValueAt(Number rowIndex
, Number colIndex
)
Returns the value at the specified data position
Parameters:
rowIndex
: NumbercolIndex
: Number
Returns:
This method is defined by DefaultDataModel.
insertRow
public function insertRow(Number index
, Array cellValues
)
Inserts a row a the specified location in the dataset.
This method is defined by DefaultDataModel.
on
public function on(String eventName
, Function handler
, [Object scope
], [boolean override
])
Appends an event handler to this element (shorthand for addListener)
Parameters:
eventName
: StringThe type of event to listen for
handler
: FunctionThe method the event invokes
scope
: Object(optional) The scope (this object) for the handler
override
: boolean(optional) If true, scope becomes the scope
Returns:
purgeListeners
public function purgeListeners()
Removes all listeners for this object
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
: ObjectThe 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
: BooleanTrue to return rows which don't match the query instead of rows that do match
Returns:
This method is defined by DefaultDataModel.
removeListener
public function removeListener(String eventName
, Function handler
, [Object scope
])
removeRow
public function removeRow(Number index
)
This method is defined by DefaultDataModel.
setDefaultSort
public function setDefaultSort(Function/Object sortInfo
, Number columnIndex
, String direction
)
Sets the default sort info. Note: this function does not actually apply the sort.
Parameters:
sortInfo
: Function/ObjectA 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
: NumberThe column index to sort by
direction
: StringThe direction of the sort ('DESC' or 'ASC')
Returns:
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
: ObjectThe new value
rowIndex
: NumbercolIndex
: Number
Returns:
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/ObjectA 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
: NumberThe column index to sort by
direction
: StringThe direction of the sort ('DESC' or 'ASC')
Returns:
This method is defined by DefaultDataModel.