Print Friendly

Class YAHOO.ext.grid.XMLDataModel

Package:YAHOO.ext.grid
Class:XMLDataModel
Extends:LoadableDataModel
Defined In:XMLDataModel.js
This is an implementation of a DataModel used by the Grid. It works with XML data.
Example schema from Amazon search:

var schema = {
tagName: 'Item',
id: 'ASIN',
fields: ['Author', 'Title', 'Manufacturer', 'ProductGroup']
};

Public Properties

Property Defined By
  addListener : Object AbstractDataModel
Inherited from Observable
  baseParams : Object LoadableDataModel
An object of key/value pairs to be passed as parameters when loading pages/sorting
  delayedListener : Object AbstractDataModel
Inherited from Observable
  fireEvent : Object AbstractDataModel
Inherited from Observable
  loadedPage : Number LoadableDataModel
The active page
  on : Object AbstractDataModel
Inherited from Observable
  onCellUpdated : YAHOO.util.CustomEvent AbstractDataModel
Deprecated. Fires when a cell is updated - fireDirect sig: (this, rowIndex, columnIndex)
  onLoad : YAHOO.util.CustomEvent LoadableDataModel
Deprecated. Fires when a successful load is completed - fireDirect sig: (this)
  onLoadException : YAHOO.util.CustomEvent LoadableDataModel
Deprecated. Fires when a load fails - fireDirect sig: (this, errorMsg, responseObj)
  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)
  pageSize : Number LoadableDataModel
The number of records per page
  pageUrl : String LoadableDataModel
The script/page to call to provide paged/sorted data
  paramMap : Object LoadableDataModel
Maps named params to url parameters - Override to specify your own param names
  remoteSort : Boolean LoadableDataModel
True to use remote sorting, initPaging automatically sets this to true
  removeListener : Object AbstractDataModel
Inherited from Observable

Public Methods

Method Defined By
  XMLDataModel(Object schema, XMLDocument xml) XMLDataModel
  addPostprocessor() : void LoadableDataModel
Adds a postprocessor function to format data before updating the underlying data source (ie. convert date to string b...
  addPreprocessor() : void LoadableDataModel
Adds a preprocessor function to parse data before it is added to the Model - ie. Date.parse to parse dates.
  addRow(String id, Array cellValues) : Number XMLDataModel
Adds a row to this DataModel and syncs the XML document
  applySort() : void DefaultDataModel
Applies the last used sort to the current data.
  createNode(XMLDocument xmlDoc, Array colData) : XMLNode XMLDataModel
Override this method to define your own node creation routine for when new rows are added. By default this method clo...
  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...
  getNamedValue() : void XMLDataModel
Convenience function looks for value in attributes, then in children tags - also normalizes namespace matches (ie ma...
  getPageSize() : void LoadableDataModel
Returns the number of records per page
  getPostprocessor() : void LoadableDataModel
Gets the postprocessor function for the specified column.
  getPreprocessor() : void LoadableDataModel
Gets the preprocessor function for the specified column.
  getRow() : Array DefaultDataModel
Returns the column data for the specified row.
  getRowCount() : void AbstractDataModel
Empty interface method - Classes which extend AbstractDataModel should implement this method. See YAHOO.ext.DefaultDa...
  getRowId(Number rowIndex) : Number XMLDataModel
Overrides getRowId in DefaultDataModel to return the ID value of the specified node.
  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...
  getTotalPages() : void LoadableDataModel
Returns the total number of pages available
  getTotalRowCount() : void AbstractDataModel
Empty interface method - Classes which extend AbstractDataModel should implement this method to support virtual row c...
  getValueAt() : void AbstractDataModel
Empty interface method - Classes which extend AbstractDataModel should implement this method. See YAHOO.ext.DefaultDa...
  initPaging() : void LoadableDataModel
Initializes paging for this model.
  insertRow(Number index, String id, Array cellValues) : Number XMLDataModel
Inserts a row into this DataModel and syncs the XML document
  isPaged() : void LoadableDataModel
Returns true if this model uses paging
  load(Object/String url, [String/Object params], [Function callback], [Number insertIndex]) : void LoadableDataModel
Initiates the loading of the data from the specified URL - Failed load attempts will fire the onLoadException event.
  loadData(XMLDocument doc, [Function callback], [Boolean keepExisting], [Number insertIndex]) : void XMLDataModel
Overrides loadData in LoadableDataModel to process XML
  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...
  removePostprocessor() : void LoadableDataModel
Removes a postprocessor function.
  removePreprocessor() : void LoadableDataModel
Removes a preprocessor function.
  removeRow(Number index) : void XMLDataModel
Removes the row from DataModel and syncs the XML document
  setNamedValue() : void XMLDataModel
Convenience function set a value in the underlying xml node.
  setValueAt(Object value, Number rowIndex, Number colIndex) : void XMLDataModel
Overrides DefaultDataModel.setValueAt to update the underlying XML Document
  sort() : void AbstractDataModel
Empty interface method - Classes which extend AbstractDataModel should implement this method. See YAHOO.ext.DefaultDa...

Public Events

This class has no public events.

Property Details

addListener

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

baseParams

public Object baseParams
An object of key/value pairs to be passed as parameters when loading pages/sorting
This property is defined by LoadableDataModel.

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.

loadedPage

public Number loadedPage
The active page
This property is defined by LoadableDataModel.

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.

onLoad

public YAHOO.util.CustomEvent onLoad
Deprecated. Fires when a successful load is completed - fireDirect sig: (this)
This property is defined by LoadableDataModel.

onLoadException

public YAHOO.util.CustomEvent onLoadException
Deprecated. Fires when a load fails - fireDirect sig: (this, errorMsg, responseObj)
This property is defined by LoadableDataModel.

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.

pageSize

public Number pageSize
The number of records per page
This property is defined by LoadableDataModel.

pageUrl

public String pageUrl
The script/page to call to provide paged/sorted data
This property is defined by LoadableDataModel.

paramMap

public Object paramMap
Maps named params to url parameters - Override to specify your own param names
This property is defined by LoadableDataModel.

remoteSort

public Boolean remoteSort
True to use remote sorting, initPaging automatically sets this to true
This property is defined by LoadableDataModel.

removeListener

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

Constructor Details

XMLDataModel

public function XMLDataModel(Object schema, XMLDocument xml)
Parameters:
  • schema : Object
    The schema to use
  • xml : XMLDocument
    An XML document to load immediately

Method Details

addPostprocessor

public function addPostprocessor()
Adds a postprocessor function to format data before updating the underlying data source (ie. convert date to string before updating XML document).
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

addPreprocessor

public function addPreprocessor()
Adds a preprocessor function to parse data before it is added to the Model - ie. Date.parse to parse dates.
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

addRow

public function addRow(String id, Array cellValues)
Adds a row to this DataModel and syncs the XML document
Parameters:
  • id : String
    The id of the row, if null the next row index is used
  • cellValues : Array
    The cell values for this row
Returns:
  • Number
    The index of the new row
This method is defined by XMLDataModel.

applySort

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

createNode

public function createNode(XMLDocument xmlDoc, Array colData)
Override this method to define your own node creation routine for when new rows are added. By default this method clones the first node and sets the column values in the newly cloned node.
Parameters:
  • xmlDoc : XMLDocument
    The xml document being used by this model
  • colData : Array
    The column data for the new node
Returns:
  • XMLNode
    The created node
This method is defined by XMLDataModel.

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.

getNamedValue

public function getNamedValue()
Convenience function looks for value in attributes, then in children tags - also normalizes namespace matches (ie matches ns:tag, FireFox matches tag and not ns:tag).
Parameters:
  • None.
Returns:
  • void
This method is defined by XMLDataModel.

getPageSize

public function getPageSize()
Returns the number of records per page
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

getPostprocessor

public function getPostprocessor()
Gets the postprocessor function for the specified column.
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

getPreprocessor

public function getPreprocessor()
Gets the preprocessor function for the specified column.
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

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()
Empty interface method - Classes which extend AbstractDataModel should implement this method. See YAHOO.ext.DefaultDataModel for an example implementation.
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

getRowId

public function getRowId(Number rowIndex)
Overrides getRowId in DefaultDataModel to return the ID value of the specified node.
Parameters:
  • rowIndex : Number
Returns:
  • Number
This method is defined by XMLDataModel.

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.

getTotalPages

public function getTotalPages()
Returns the total number of pages available
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

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()
Empty interface method - Classes which extend AbstractDataModel should implement this method. See YAHOO.ext.DefaultDataModel for an example implementation.
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

initPaging

public function initPaging()
Initializes paging for this model.
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

insertRow

public function insertRow(Number index, String id, Array cellValues)
Inserts a row into this DataModel and syncs the XML document
Parameters:
  • index : Number
    The index to insert the row
  • id : String
    The id of the row, if null the next row index is used
  • cellValues : Array
    The cell values for this row
Returns:
  • Number
    The index of the new row
This method is defined by XMLDataModel.

isPaged

public function isPaged()
Returns true if this model uses paging
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

load

public function load(Object/String url, [String/Object params], [Function callback], [Number insertIndex])
Initiates the loading of the data from the specified URL - Failed load attempts will fire the onLoadException event.
Parameters:
  • url : Object/String
    The url from which the data can be loaded
  • params : String/Object
    (optional) The parameters to pass as either a url encoded string "param1=1&param2=2" or as an object {param1: 1, param2: 2}
  • callback : Function
    (optional) Callback when load is complete - called with signature (this, rowCountLoaded)
  • insertIndex : Number
    (optional) if present, loaded data is inserted at the specified index instead of overwriting existing data
Returns:
  • void
This method is defined by LoadableDataModel.

loadData

public function loadData(XMLDocument doc, [Function callback], [Boolean keepExisting], [Number insertIndex])
Overrides loadData in LoadableDataModel to process XML
Parameters:
  • doc : XMLDocument
    The document to load
  • callback : Function
    (optional) callback to call when loading is complete
  • keepExisting : Boolean
    (optional) true to keep existing data
  • insertIndex : Number
    (optional) if present, loaded data is inserted at the specified index instead of overwriting existing data
Returns:
  • void
This method is defined by XMLDataModel.

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.

removePostprocessor

public function removePostprocessor()
Removes a postprocessor function.
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

removePreprocessor

public function removePreprocessor()
Removes a preprocessor function.
Parameters:
  • None.
Returns:
  • void
This method is defined by LoadableDataModel.

removeRow

public function removeRow(Number index)
Removes the row from DataModel and syncs the XML document
Parameters:
  • index : Number
    The index of the row to remove
Returns:
  • void
This method is defined by XMLDataModel.

setNamedValue

public function setNamedValue()
Convenience function set a value in the underlying xml node.
Parameters:
  • None.
Returns:
  • void
This method is defined by XMLDataModel.

setValueAt

public function setValueAt(Object value, Number rowIndex, Number colIndex)
Overrides DefaultDataModel.setValueAt to update the underlying XML Document
Parameters:
  • value : Object
    The new value
  • rowIndex : Number
  • colIndex : Number
Returns:
  • void
This method is defined by XMLDataModel.

sort

public function sort()
Empty interface method - Classes which extend AbstractDataModel should implement this method. See YAHOO.ext.DefaultDataModel for an example implementation.
Parameters:
  • None.
Returns:
  • void
This method is defined by AbstractDataModel.

Copyright © 2006 Jack Slocum. All rights reserved.