Print Friendly

Class YAHOO.widget.DataSource

Package:YAHOO.widget
Class:DataSource
Extends:Object
Subclasses:DS_JSArray, DS_JSFunction, DS_XHR
Defined In:autocomplete.js
The DataSource classes manages sending a request and returning response from a live database. Supported data include local JavaScript arrays and objects and databases accessible via XHR connections. Supported response formats include JavaScript arrays, JSON, XML, and flat-file textual data.

Public Properties

Property Defined By
  ERROR_DATANULL : String DataSource
<static> Error message for null data responses.
  ERROR_DATAPARSE : String DataSource
<static> Error message for data responses with parsing errors.
  maxCacheEntries : Number DataSource
Max size of the local cache. Set to 0 to turn off caching. Caching is useful to reduce the number of server connect...
  queryMatchCase : Boolean DataSource
Enables query case-sensitivity matching. If caching is on and queryMatchCase is true, queries will only return result...
  queryMatchContains : Boolean DataSource
Use this to equate cache matching with the type of matching done by your live data source. If caching is on and query...
  queryMatchSubset : Boolean DataSource
Enables query subset matching. If caching is on and queryMatchSubset is true, substrings of queries will return match...

Public Methods

Method Defined By
  DataSource() DataSource
  doQuery(oCallbackFn {HTMLFunction}, sQuery {String}, oParent {Object}) : void DataSource
Abstract method implemented by subclasses to make a query to the live data source. Must call the callback function wi...
  flushCache() : void DataSource
Flushes cache.
  getResults(oCallbackFn {HTMLFunction}, sQuery {String}, oParent {Object}) : void DataSource
Retrieves query results, first checking the local cache, then making the query request to the live data source as def...
  toString() : String DataSource
Public accessor to the unique name of the DataSource instance.

Public Events

Event Defined By
  cacheFlushEvent : (oSelf {Object}) DataSource
Fired when the local cache is flushed.
  cacheQueryEvent : (oSelf {Object}, oParent {Object}, sQuery {String}) DataSource
Fired when a query is made to the local cache.
  dataErrorEvent : (oSelf {Object}, oParent {Object}, sQuery {String}, sMsg {String}) DataSource
Fired when an error is encountered with the live data source.
  getCachedResultsEvent : (oSelf {Object}, oParent {Object}, sQuery {String}, aResults {Object[]}) DataSource
Fired when data is retrieved from the local cache.
  getResultsEvent : (oSelf {Object}, oParent {Object}, sQuery {String}, aResults {Object[]}) DataSource
Fired when data is retrieved from the live data source.
  queryEvent : (oSelf {Object}, oParent {Object}, sQuery {String}) DataSource
Fired when a query is made to the live data source.

Property Details

ERROR_DATANULL

public String ERROR_DATANULL
<static> Error message for null data responses.
This property is defined by DataSource.

ERROR_DATAPARSE

public String ERROR_DATAPARSE
<static> Error message for data responses with parsing errors.
This property is defined by DataSource.

maxCacheEntries

public Number maxCacheEntries
Max size of the local cache. Set to 0 to turn off caching. Caching is useful to reduce the number of server connections. Recommended only for data sources that return comprehensive results for queries or when stale data is not an issue.
This property is defined by DataSource.

queryMatchCase

public Boolean queryMatchCase
Enables query case-sensitivity matching. If caching is on and queryMatchCase is true, queries will only return results for case-sensitive matches.
This property is defined by DataSource.

queryMatchContains

public Boolean queryMatchContains
Use this to equate cache matching with the type of matching done by your live data source. If caching is on and queryMatchContains is true, the cache returns results that "contain" the query string. By default, queryMatchContains is set to false, meaning the cache only returns results that "start with" the query string.
This property is defined by DataSource.

queryMatchSubset

public Boolean queryMatchSubset
Enables query subset matching. If caching is on and queryMatchSubset is true, substrings of queries will return matching cached results. For instance, if the first query is for "abc" susequent queries that start with "abc", like "abcd", will be queried against the cache, and not the live data source. Recommended only for DataSources that return comprehensive results for queries with very few characters.
This property is defined by DataSource.

Constructor Details

DataSource

public function DataSource()
Parameters:
  • None.

Method Details

doQuery

public function doQuery(oCallbackFn {HTMLFunction}, sQuery {String}, oParent {Object})
Abstract method implemented by subclasses to make a query to the live data source. Must call the callback function with the response returned from the query. Populates cache (if enabled).
Parameters:
  • {HTMLFunction} : oCallbackFn
    Callback function implemented by oParent to which to return results.
  • {String} : sQuery
    Query string.
  • {Object} : oParent
    The object instance that has requested data.
Returns:
  • void
This method is defined by DataSource.

flushCache

public function flushCache()
Flushes cache.
Parameters:
  • None.
Returns:
  • void
This method is defined by DataSource.

getResults

public function getResults(oCallbackFn {HTMLFunction}, sQuery {String}, oParent {Object})
Retrieves query results, first checking the local cache, then making the query request to the live data source as defined by the function doQuery.
Parameters:
  • {HTMLFunction} : oCallbackFn
    Callback function defined by oParent object to which to return results.
  • {String} : sQuery
    Query string.
  • {Object} : oParent
    The object instance that has requested data.
Returns:
  • void
This method is defined by DataSource.

toString

public function toString()
Public accessor to the unique name of the DataSource instance.
Parameters:
  • None.
Returns:
  • String
    Unique name of the DataSource instance
This method is defined by DataSource.

Event Details

cacheFlushEvent

public event cacheFlushEvent
Fired when the local cache is flushed.
Subscribers will be called with the following parameters:
  • {Object} : oSelf
    The DataSource instance
This event is defined by DataSource.

cacheQueryEvent

public event cacheQueryEvent
Fired when a query is made to the local cache.
Subscribers will be called with the following parameters:
  • {Object} : oSelf
    The DataSource instance.
  • {Object} : oParent
    The requesting object.
  • {String} : sQuery
    The query string.
This event is defined by DataSource.

dataErrorEvent

public event dataErrorEvent
Fired when an error is encountered with the live data source.
Subscribers will be called with the following parameters:
  • {Object} : oSelf
    The DataSource instance.
  • {Object} : oParent
    The requesting object.
  • {String} : sQuery
    The query string.
  • {String} : sMsg
    Error message string
This event is defined by DataSource.

getCachedResultsEvent

public event getCachedResultsEvent
Fired when data is retrieved from the local cache.
Subscribers will be called with the following parameters:
  • {Object} : oSelf
    The DataSource instance.
  • {Object} : oParent
    The requesting object.
  • {String} : sQuery
    The query string.
  • {Object[]} : aResults
    Array of result objects.
This event is defined by DataSource.

getResultsEvent

public event getResultsEvent
Fired when data is retrieved from the live data source.
Subscribers will be called with the following parameters:
  • {Object} : oSelf
    The DataSource instance.
  • {Object} : oParent
    The requesting object.
  • {String} : sQuery
    The query string.
  • {Object[]} : aResults
    Array of result objects.
This event is defined by DataSource.

queryEvent

public event queryEvent
Fired when a query is made to the live data source.
Subscribers will be called with the following parameters:
  • {Object} : oSelf
    The DataSource instance.
  • {Object} : oParent
    The requesting object.
  • {String} : sQuery
    The query string.
This event is defined by DataSource.

yui-ext - Copyright © 2006 Jack Slocum. | Yahoo! UI - Copyright © 2006 Yahoo! Inc.
All rights reserved.