com.gwtext.client.data
Class Store

java.lang.Object
  extended by com.gwtext.client.core.JsObject
      extended by com.gwtext.client.data.Store
Direct Known Subclasses:
GroupingStore, JsonStore, SimpleStore

public class Store
extends JsObject

The Store class encapsulates a client side cache of Record objects which provide input data for widgets such as the GridPanel, or the ComboBox.

A Store object uses an implementation of DataProxy to access a data object unless you call loadData() directly and pass in your data. The Store object has no knowledge of the format of the data returned by the Proxy.

A Store object uses its configured implementation of Reader to Record instances from the data object. These records are cached and made available through accessor functions. Usage :

 
 

Object[][] states = new Object[][]{ new Object[]{"AL", "Alabama"}, new Object[]{"AK", "Alaska"}, new Object[]{"AZ", "Arizona"}, new Object[]{"AR", "Arkansas"}, new Object[]{"CA", "California"}};

Reader reader = new ArrayReader(new RecordDef( new FieldDef[]{ new StringFieldDef("abbr"), new StringFieldDef("state") }));

Store store = new Store(proxy, reader);

See Also:
XmlReader, JsonReader, HttpProxy, MemoryProxy

Field Summary
protected  com.google.gwt.core.client.JavaScriptObject configJS
           
 
Fields inherited from class com.gwtext.client.core.JsObject
jsObj
 
Constructor Summary
protected Store()
           
  Store(DataProxy dataProxy, Reader reader)
          Create a Store using the specified DataProxy and Reader.
  Store(DataProxy dataProxy, Reader reader, boolean remoteSort)
          Create a Store using the specified DataProxy and Reader.
  Store(DataProxy dataProxy, Reader reader, UrlParam[] baseParams, SortState initialSortState, boolean remoteSort)
          Create a Store using the specified configuration.
  Store(com.google.gwt.core.client.JavaScriptObject jsObj)
           
  Store(Reader reader)
          Create a Store using the specified Reader.
  Store(RecordDef recordDef)
          Create a Store using the specified RecordDef.
 
Method Summary
 void add(Record record)
          Add a Record to the Store and fires the add event.
 void add(Record[] records)
          Add Records to the Store and fires the add event.
 void addSorted(Record record)
          (Local sort only) Inserts the passed the record in the Store at the index where it should go based on the current sort information.
 void addStoreListener(StoreListener listener)
          Add a Store listener.
 void clearFilter()
          Revert to a view of the Record cache / snapshot with no filtering applied.
 void clearFilter(boolean suppressEvent)
          Revert to a view of the Record cache with no filtering applied.
 void clearSortState(boolean reload)
          Clears the Stores internal sort state.
 void commitChanges()
          Commit all Records with outstanding changes.
 void each(StoreTraversalCallback cb)
          Calls the specified function for each of the Records in the cache.
 void filter(java.lang.String field, RegExp regexp)
          Filter the records by a specified property using a Regular expression.
 void filter(java.lang.String field, java.lang.String value)
          Filter the records by a specified property .
 void filter(java.lang.String field, java.lang.String value, boolean anyMatch)
          Filter the records by a specified property .
 void filterBy(StoreTraversalCallback cb)
          Filter by a function.
 int find(java.lang.String propname, java.lang.String value, int startIndex, boolean anymatch, boolean casesensitive)
          Finds the index of the first matching record in this store by a specific property/value.
 Record getAt(int index)
          Returns the record at the specified index.
 UrlParam[] getBaseParams()
          Return the base params.
 Record getById(java.lang.String id)
          Get the Record with the specified id.
 int getCount()
          Gets the number of cached records.
 java.lang.String[] getFields()
           
 com.google.gwt.core.client.JavaScriptObject getJsObj()
           
 Record[] getModifiedRecords()
          Gets all records modified since the last commit.
 Record[] getRange(int startIndex, int endIndex)
          Returns a range of Records between specified indices.
 Record getRecordAt(int index)
          Returns the record at the specified index.
 Record[] getRecords()
          Return all the Records in the Store.
 com.google.gwt.core.client.JavaScriptObject getRecordsAsJS()
           
 SortState getSortState()
          Returns the sort state of the Store.
 int getTotalCount()
          Gets the total number of records in the dataset as returned by the server.
 int indexOf(Record record)
          Get the index within the cache of the passed Record.
 int indexOfId(java.lang.String id)
          Get the index within the cache of the Record with the passed id.
 void insert(int index, Record record)
          Inserts Records to the Store at the given index and fires the add event.
 void insert(int index, Record[] records)
          Inserts Records to the Store at the given index and fires the add event.
 void load()
          Loads the Record cache from the configured Proxy using the configured Reader.
 void load(int start, int limit)
          Loads the Record cache from the configured Proxy using the configured Reader.
 void load(UrlParam[] params)
          Loads the Record cache from the configured Proxy using the configured Reader.
 void load(UrlParam[] params, boolean add)
          Loads the Record cache from the configured Proxy using the configured Reader.
 void loadJsonData(java.lang.String jsonString, boolean append)
          Load data from a local Json String
 void loadXmlData(java.lang.String xmlString, boolean append)
          Load data from a local XML String.
 void loadXmlDataFromUrl(java.lang.String url, boolean append)
          Load data from XML returned from a URL.
 Record[] query(java.lang.String field, RegExp regexp)
          Query the records by a specified property.
 Record[] query(java.lang.String field, java.lang.String value)
          Query the records by a specified property.
 Record[] query(java.lang.String field, java.lang.String value, boolean anyMatch)
          Query the records by a specified property.
 Record[] queryBy(StoreQueryFunction queryFunction)
          Query by a function.
 void rejectChanges()
          Cancel outstanding changes on all changed records.
 void reload()
          Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.
 void reload(UrlParam[] params)
          Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.
 void reload(UrlParam[] params, boolean add)
          Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.
 void remove(Record record)
          Remove a Record from the Store and fires the remove event.
 void removeAll()
          Remove all Records from the Store and fires the clear event.
 void setAutoLoad(boolean autoLoad)
          If true, this store's load method is automatically called after creation.
 void setBaseParams(UrlParam[] baseParams)
          Url params which are to be sent as parameters on any HTTP request.
 void setDataProxy(DataProxy proxy)
          The Proxy object which provides access to a data object..
 void setDefaultSort(java.lang.String field, SortDir sortDir)
          Sets the default sort column and order to be used by the next load operation.
 void setDefaultSort(java.lang.String field, java.lang.String sortDir)
          Deprecated. Use setDefaultSort(String, com.gwtext.client.core.SortDir)
 void setInitialSortState(SortState initialSortState)
          Set the initial sort state.
 void setPruneModifiedRecords(boolean pruneModifiedRecords)
          True to clear all modified record information each time the store is loaded or when a record is removed.
 void setReader(Reader reader)
          The Reader object which processes the data object and returns an Array of Ext.data.record objects which are cached keyed by their id property.
 void setRecordDef(RecordDef recordDef)
          Sets the record def for the Store.
 void setRemoteSort(boolean remoteSort)
          True if sorting is to be handled by requesting the Proxy to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
 void setSortInfo(SortState sortInfo)
          The initial field to sort and its direction
 void setStoreId(java.lang.String storeId)
          If passed, the id to use to register with the StoreMgr.
 void setUrl(java.lang.String url)
          If passed, an HttpProxy is created for the passed URL.
 void sort(java.lang.String field)
          Sort the Records.
 void sort(java.lang.String field, SortDir direction)
          Sort the Records.
 void sort(java.lang.String field, java.lang.String direction)
          Deprecated. Use sort(String, com.gwtext.client.core.SortDir)
 float sum(java.lang.String field)
          Sums the value of property for each record between start and end and returns the result.
 float sum(java.lang.String field, int startIndex, int endIndex)
          Sums the value of property for each record between start and end and returns the result.
 
Methods inherited from class com.gwtext.client.core.JsObject
getProperties, isCreated, setJsObj
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configJS

protected com.google.gwt.core.client.JavaScriptObject configJS
Constructor Detail

Store

protected Store()

Store

public Store(com.google.gwt.core.client.JavaScriptObject jsObj)

Store

public Store(RecordDef recordDef)
Create a Store using the specified RecordDef. Data can be added to the Store using add(Record)

Parameters:
recordDef - the record def

Store

public Store(Reader reader)
Create a Store using the specified Reader.

Parameters:
reader - the reader

Store

public Store(DataProxy dataProxy,
             Reader reader)
Create a Store using the specified DataProxy and Reader.

Parameters:
dataProxy - the data proxy
reader - the reader

Store

public Store(DataProxy dataProxy,
             Reader reader,
             boolean remoteSort)
Create a Store using the specified DataProxy and Reader.

Parameters:
dataProxy - the data proxy
reader - the reader
remoteSort - true to enable remote sort of the data

Store

public Store(DataProxy dataProxy,
             Reader reader,
             UrlParam[] baseParams,
             SortState initialSortState,
             boolean remoteSort)
Create a Store using the specified configuration.

Parameters:
dataProxy - the data proxy
reader - the reader
baseParams - base params which are to be sent as parameters on any HTTP request. Used only for Http based proxies.
initialSortState - the initial sort field name and direction
remoteSort - true to enable remote sort
Method Detail

getJsObj

public com.google.gwt.core.client.JavaScriptObject getJsObj()
Overrides:
getJsObj in class JsObject

getBaseParams

public UrlParam[] getBaseParams()
Return the base params.

Returns:
the base params

add

public void add(Record record)
Add a Record to the Store and fires the add event.

Parameters:
record - the Record to add

add

public void add(Record[] records)
Add Records to the Store and fires the add event.

Parameters:
records - the Records to add

addSorted

public void addSorted(Record record)
(Local sort only) Inserts the passed the record in the Store at the index where it should go based on the current sort information.

Parameters:
record - the record to add

clearSortState

public void clearSortState(boolean reload)
Clears the Stores internal sort state.

Parameters:
reload - true to reload the store after clearing the sort state

clearFilter

public void clearFilter()
Revert to a view of the Record cache / snapshot with no filtering applied. A snapshot of the data is taken when filter(String, String) is called. Records added to the Store after filter is caleld will be lost if clearFilter is subsequently called.


clearFilter

public void clearFilter(boolean suppressEvent)
Revert to a view of the Record cache with no filtering applied.

Parameters:
suppressEvent - if true the filter is cleared silently without notifying listeners

commitChanges

public void commitChanges()
Commit all Records with outstanding changes. To handle updates for changes, subscribe to the Store's "update" event, and perform updating when the third parameter Record.COMMIT.


each

public void each(StoreTraversalCallback cb)
Calls the specified function for each of the Records in the cache.

Parameters:
cb - the Store traversal callback

filter

public void filter(java.lang.String field,
                   RegExp regexp)
Filter the records by a specified property using a Regular expression.

Parameters:
field - the filed to filter on
regexp - the regular expression to test field value against

filter

public void filter(java.lang.String field,
                   java.lang.String value)
Filter the records by a specified property .

Parameters:
field - the filed to filter on
value - a string that the field should start with

filter

public void filter(java.lang.String field,
                   java.lang.String value,
                   boolean anyMatch)
Filter the records by a specified property .

Parameters:
field - the filed to filter on
value - a string that the field should start with
anyMatch - true to match any part not just the beginning

filterBy

public void filterBy(StoreTraversalCallback cb)
Filter by a function. The specified function will be called with each record in this data source. If the function returns true the record is included, otherwise it is filtered.

Parameters:
cb - the filter function

find

public int find(java.lang.String propname,
                java.lang.String value,
                int startIndex,
                boolean anymatch,
                boolean casesensitive)
Finds the index of the first matching record in this store by a specific property/value.

Parameters:
propname - the property name
value - the string that the property value should begin with
startIndex - the index to start searching at
anymatch - true to match any part of the string, not just the beginning
casesensitive - true for case sensitive comparison
Returns:
the matched index or -1

getRecordAt

public Record getRecordAt(int index)
Returns the record at the specified index. This method is functionally equivalent to getAt(int).

Parameters:
index - the Store index
Returns:
the Record at index

getAt

public Record getAt(int index)
Returns the record at the specified index.

Parameters:
index - the Store index
Returns:
the Record at index

getById

public Record getById(java.lang.String id)
Get the Record with the specified id.

Parameters:
id - the Record ID
Returns:
the matched Record or null if no match found

getCount

public int getCount()
Gets the number of cached records. If using paging, this may not be the total size of the dataset. If the data object used by the Reader contains the dataset size, then the getTotalCount() function returns the data set size

Returns:
the Record count

getModifiedRecords

public Record[] getModifiedRecords()
Gets all records modified since the last commit. Modified records are persisted across load operations (e.g., during paging).

Returns:
the modified Records. Returns an empty array if no records were modified

getRange

public Record[] getRange(int startIndex,
                         int endIndex)
Returns a range of Records between specified indices.

Parameters:
startIndex - the starting index (0 based)
endIndex - the ending index
Returns:
array of Records

getSortState

public SortState getSortState()
Returns the sort state of the Store.

Returns:
the Store sort state

getTotalCount

public int getTotalCount()
Gets the total number of records in the dataset as returned by the server. If using paging, for this to be accurate, the data object used by the Reader must contain the dataset size.

Returns:
total record count

indexOf

public int indexOf(Record record)
Get the index within the cache of the passed Record.

Parameters:
record - the Record to find
Returns:
the index of the passed Record. Returns -1 if not found

indexOfId

public int indexOfId(java.lang.String id)
Get the index within the cache of the Record with the passed id.

Parameters:
id - the Record ID
Returns:
the index of the Record. Returns -1 if not found

insert

public void insert(int index,
                   Record record)
Inserts Records to the Store at the given index and fires the add event.

Parameters:
index - the start index at which to insert the passed Record
record - the Record to insert

insert

public void insert(int index,
                   Record[] records)
Inserts Records to the Store at the given index and fires the add event.

Parameters:
index - the start index at which to insert the passed Records
records - the Records to insert

load

public void load()
Loads the Record cache from the configured Proxy using the configured Reader.

If using remote paging, then the first load call must specify the start and limit properties to establish the initial position within the dataset by calling load(int, int) , and the number of Records to cache on each read from the Proxy. It is important to note that for remote data sources, loading is asynchronous, and this call will return before the new data has been loaded. Perform any post-processing in a "load" event handler.


load

public void load(int start,
                 int limit)
Loads the Record cache from the configured Proxy using the configured Reader.

If using remote paging, then the first load call must specify the start and limit properties to establish the initial position within the dataset by calling load(int, int) , and the number of Records to cache on each read from the Proxy. It is important to note that for remote data sources, loading is asynchronous, and this call will return before the new data has been loaded. Perform any post-processing in a "load" event handler.

Parameters:
start - start position
limit - limit

load

public void load(UrlParam[] params)
Loads the Record cache from the configured Proxy using the configured Reader.

If using remote paging, then the first load call must specify the start and limit properties to establish the initial position within the dataset by calling load(int, int) , and the number of Records to cache on each read from the Proxy. It is important to note that for remote data sources, loading is asynchronous, and this call will return before the new data has been loaded. Perform any post-processing in a "load" event handler.

Parameters:
params - the load params

load

public void load(UrlParam[] params,
                 boolean add)
Loads the Record cache from the configured Proxy using the configured Reader.

If using remote paging, then the first load call must specify the start and limit properties to establish the initial position within the dataset by calling load(int, int) , and the number of Records to cache on each read from the Proxy. It is important to note that for remote data sources, loading is asynchronous, and this call will return before the new data has been loaded. Perform any post-processing in a "load" event handler.

Parameters:
params - the load params
add - true to append loaded records rather than replace the current cache

reload

public void reload()
Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.


loadJsonData

public void loadJsonData(java.lang.String jsonString,
                         boolean append)
Load data from a local Json String

Parameters:
jsonString - the Json String
append - true to append to the Store

loadXmlDataFromUrl

public void loadXmlDataFromUrl(java.lang.String url,
                               boolean append)
Load data from XML returned from a URL.

Parameters:
url - the url that returns the XML data
append - true to append records

loadXmlData

public void loadXmlData(java.lang.String xmlString,
                        boolean append)
Load data from a local XML String.

Parameters:
xmlString - the XML data
append - true to append records

reload

public void reload(UrlParam[] params)
Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.

Parameters:
params - the request params

reload

public void reload(UrlParam[] params,
                   boolean add)
Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.

Parameters:
params - the request params
add - true to append loaded records rather than replace the current cache

query

public Record[] query(java.lang.String field,
                      java.lang.String value)
Query the records by a specified property.

Parameters:
field - the field to query on
value - a string that the field should start with
Returns:
array of match records or empty array if no match found

query

public Record[] query(java.lang.String field,
                      java.lang.String value,
                      boolean anyMatch)
Query the records by a specified property.

Parameters:
field - the field to query on
value - a string that the field should start with
anyMatch - true to match any part not just the beginning
Returns:
array of match records or empty array if no match found

query

public Record[] query(java.lang.String field,
                      RegExp regexp)
Query the records by a specified property.

Parameters:
field - the field to query on
regexp - a RegExp to test against the field
Returns:
array of match records or empty array if no match found

queryBy

public Record[] queryBy(StoreQueryFunction queryFunction)
Query by a function. The specified function will be called with each record in this data source. If the function returns true the record is included in the results.

Parameters:
queryFunction - the query function
Returns:
array of match records or empty array if no match found

rejectChanges

public void rejectChanges()
Cancel outstanding changes on all changed records.


remove

public void remove(Record record)
Remove a Record from the Store and fires the remove event.

Parameters:
record - the record to remove

removeAll

public void removeAll()
Remove all Records from the Store and fires the clear event.


setDefaultSort

public void setDefaultSort(java.lang.String field,
                           SortDir sortDir)
Sets the default sort column and order to be used by the next load operation.

Parameters:
field - the name of the field to sort by
sortDir - the sort order

setDefaultSort

public void setDefaultSort(java.lang.String field,
                           java.lang.String sortDir)
Deprecated. Use setDefaultSort(String, com.gwtext.client.core.SortDir)

Sets the default sort column and order to be used by the next load operation.

Parameters:
field - the name of the field to sort by
sortDir - the sort order, "ASC" or "DESC" (defaults to "ASC")

sort

public void sort(java.lang.String field)
Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local sorting is used, the cache is sorted internally.

Parameters:
field - the name of the field to sort by

sort

public void sort(java.lang.String field,
                 SortDir direction)
Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local sorting is used, the cache is sorted internally.

Parameters:
field - the name of the field to sort by
direction - the sort order

sort

public void sort(java.lang.String field,
                 java.lang.String direction)
Deprecated. Use sort(String, com.gwtext.client.core.SortDir)

Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local sorting is used, the cache is sorted internally.

Parameters:
field - the name of the field to sort by
direction - the sort order, "ASC" or "DESC" (defaults to "ASC")

sum

public float sum(java.lang.String field)
Sums the value of property for each record between start and end and returns the result.

Parameters:
field - field on your records
Returns:
the sum

sum

public float sum(java.lang.String field,
                 int startIndex,
                 int endIndex)
Sums the value of property for each record between start and end and returns the result.

Parameters:
field - field on your records
startIndex - the record index to start at (defaults to 0)
endIndex - the last record index to include
Returns:
the sum

getRecords

public Record[] getRecords()
Return all the Records in the Store.

Returns:
the Records

addStoreListener

public void addStoreListener(StoreListener listener)
Add a Store listener.

Parameters:
listener - the listener

setAutoLoad

public void setAutoLoad(boolean autoLoad)
If true, this store's load method is automatically called after creation.

Parameters:
autoLoad - true to auto laod

setBaseParams

public void setBaseParams(UrlParam[] baseParams)
Url params which are to be sent as parameters on any HTTP request.

Parameters:
baseParams - the base params

setDataProxy

public void setDataProxy(DataProxy proxy)
The Proxy object which provides access to a data object..

Parameters:
proxy - the data proxy

setPruneModifiedRecords

public void setPruneModifiedRecords(boolean pruneModifiedRecords)
True to clear all modified record information each time the store is loaded or when a record is removed. (defaults to false).

Parameters:
pruneModifiedRecords - true to prune modified records

setReader

public void setReader(Reader reader)
The Reader object which processes the data object and returns an Array of Ext.data.record objects which are cached keyed by their id property.

Parameters:
reader - the reader

setRemoteSort

public void setRemoteSort(boolean remoteSort)
True if sorting is to be handled by requesting the Proxy to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false). If remote sorting is specified, then clicking on a column header causes the current page to be requested from the server with the addition of the following two parameters:

sort : String The name (as specified in the Record's Field definition) of the field to sort on. dir : String The direction of the sort, "ASC" or "DESC".

Parameters:
remoteSort - true to enable remote sort

setSortInfo

public void setSortInfo(SortState sortInfo)
The initial field to sort and its direction

Parameters:
sortInfo - the sort info

setStoreId

public void setStoreId(java.lang.String storeId)
If passed, the id to use to register with the StoreMgr.

Parameters:
storeId - the store ID

setUrl

public void setUrl(java.lang.String url)
If passed, an HttpProxy is created for the passed URL.

Parameters:
url - the url

setRecordDef

public void setRecordDef(RecordDef recordDef)
Sets the record def for the Store.

Parameters:
recordDef - the stores record def

setInitialSortState

public void setInitialSortState(SortState initialSortState)
Set the initial sort state.

Parameters:
initialSortState - the initial sort state

getRecordsAsJS

public com.google.gwt.core.client.JavaScriptObject getRecordsAsJS()

getFields

public java.lang.String[] getFields()