Properties Methods Events Config Options Direct Link

    Observable
      Store
        SimpleStore

# Class Ext.data.SimpleStore

Package: | Ext.data
Defined In: | SimpleStore.js
Class: | SimpleStore
Extends: | Store

Small helper class to make creating Stores from Array data easier.

## Config Options

Config Options | Defined By
--- | ---
| autoLoad : Boolean/Object If passed, this store's load method is automatically called after creation with the autoLoad object | Store
| baseParams : Object An object containing properties which are to be sent as parameters on any HTTP request | Store
| data : Array The multi-dimensional array of data | SimpleStore
| fields : Array An array of field definition objects, or field name strings. | SimpleStore
| id : Number The array index of the record id. Leave blank to auto generate ids. | SimpleStore
| listeners : Object A config object containing one or more event handlers to be added to this object during initialization. This should b... A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once. | Observable
| proxy : Ext.data.DataProxy The Proxy object which provides access to a data object. | Store
| pruneModifiedRecords : boolean True to clear all modified record information each time the store is loaded or when a record is removed. (defaults to... True to clear all modified record information each time the store is loaded or when a record is removed. (defaults to false). | Store
| reader : Ext.data.Reader The Reader object which processes the data object and returns an Array of Ext.data.record objects which are cached ke... 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. | Store

remoteSort : boolean
True if sorting is to be handled by requesting the Proxy to provide a refreshed version of the data object in sorted ...
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".

Store

| sortInfo : Object A config object in the format: {field: "fieldName", direction: "ASC|DESC"} | Store
| storeId : String If passed, the id to use to register with the StoreMgr | Store
| url : String If passed, an HttpProxy is created for the passed URL | Store

## Public Properties

Property | Defined By
--- | ---
| baseParams : Object An object containing properties which are used as parameters on any HTTP request. | Store
| lastOptions : Object Contains the last options object used as the parameter to the load method. See load for the details of what this may ... Contains the last options object used as the parameter to the load method. See load for the details of what this may contain. This may be useful for accessing any params which were used to load the current Record cache. | Store

## Public Methods

Method | Defined By
--- | ---

SimpleStore( `Object config` )
Parameters:

- `config` : Object

Returns:

- ``

SimpleStore

add( `Ext.data.Record[] records` ) : void
Add Records to the Store and fires the add event.
Add Records to the Store and fires the add event.
Parameters:

- `records` : Ext.data.Record[]
  An Array of Ext.data.Record objects to add to the cache.

Returns:

- `void`

Store

addEvents( `Object object` ) : void
Used to define events on this Observable
Used to define events on this Observable
Parameters:

- `object` : Object
  The object with the events defined

Returns:

- `void`

Observable

addListener( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void
Appends an event handler to this component
Appends an event handler to this component
Parameters:

- `eventName` : String
  The type of event to listen for
- `handler` : Function
  The method the event invokes
- `scope` : Object
  (optional) The scope in which to execute the handler function. The handler function's "this" context.
- `options` : Object
  (optional) An object containing handler configuration properties. This may contain any of the following properties:
  - scope : Object

    The scope in which to execute the handler function. The handler function's "this" context.

  - delay : Number

    The number of milliseconds to delay the invocation of the handler after the event fires.

  - single : Boolean

    True to add a handler to handle just the next firing of the event, and then remove itself.

  - buffer {Number} Causes the handler to be scheduled to run in an Ext.util.DelayedTask delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place.

  Combining Options
  Using the options argument, it is possible to combine different types of listeners:
  A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)

      el.on('click', this.onClick, this, {
          single: true,
          delay: 100,
          forumId: 4
      });

  Attaching multiple handlers in 1 call
  The method also allows for a single argument to be passed which is a config object containing properties which specify multiple handlers.

      foo.on({
          'click' : {
              fn: this.onClick,
              scope: this,
              delay: 100
          },
          'mouseover' : {
              fn: this.onMouseOver,
              scope: this
          },
          'mouseout' : {
              fn: this.onMouseOut,
              scope: this
          }
      });

  Or a shorthand syntax:

      foo.on({
          'click' : this.onClick,
          'mouseover' : this.onMouseOver,
          'mouseout' : this.onMouseOut,
           scope: this
      });

Returns:

- `void`

Observable

addSorted( `Ext.data.Record record` ) : void
(Local sort only) Inserts the passed the record in the Store at the index where it should go based on the current sor...
(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` : Ext.data.Record

Returns:

- `void`

Store

clearFilter( `Boolean suppressEvent` ) : void
Revert to a view of the Record cache with no filtering applied.
Revert to a view of the Record cache with no filtering applied.
Parameters:

- `suppressEvent` : Boolean
  If true the filter is cleared silently without notifying listeners

Returns:

- `void`

Store

collect( `String dataIndex`, [`Boolean allowNull`], [`Boolean bypassFilter`] ) : Array
Collects unique values for a particular dataIndex from this store.
Collects unique values for a particular dataIndex from this store.
Parameters:

- `dataIndex` : String
  The property to collect
- `allowNull` : Boolean
  (optional) Pass true to allow null, undefined or empty string values
- `bypassFilter` : Boolean
  (optional) Pass true to collect from all records, even ones which are filtered

Returns:

- `Array`
  An array of the unique values

Store

commitChanges() : void
Commit all Records with outstanding changes. To handle updates for changes, subscribe to the Store's "update" event, ...
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 is Ext.data.Record.COMMIT.
Parameters:

- None.

Returns:

- `void`

Store

each( `Function fn`, [`Object scope`] ) : void
Calls the specified function for each of the Records in the cache.
Calls the specified function for each of the Records in the cache.
Parameters:

- `fn` : Function
  The function to call. The Record is passed as the first parameter. Returning `false` aborts and exits the iteration.
- `scope` : Object
  (optional) The scope in which to call the function (defaults to the Record).

Returns:

- `void`

Store

filter( `String field`, `String/RegExp value`, [`Boolean anyMatch`], [`Boolean caseSensitive`] ) : void
Filter the records by a specified property.
Filter the records by a specified property.
Parameters:

- `field` : String
  A field on your records
- `value` : String/RegExp
  Either a string that the field should start with or a RegExp to test against the field
- `anyMatch` : Boolean
  (optional) True to match any part not just the beginning
- `caseSensitive` : Boolean
  (optional) True for case sensitive comparison

Returns:

- `void`

Store

filterBy( `Function fn`, [`Object scope`] ) : void
Filter by a function. The specified function will be called for each Record in this Store. If the function returns tr...
Filter by a function. The specified function will be called for each Record in this Store. If the function returns `true` the Record is included, otherwise it is filtered out.
Parameters:

- `fn` : Function
  The function to be called. It will be passed the following parameters:
  - record : Ext.data.Record

    The record to test for filtering. Access field values using Ext.data.Record.get.

  - id : Object

    The ID of the Record passed.

- `scope` : Object
  (optional) The scope of the function (defaults to this)

Returns:

- `void`

Store

find( `String property`, `String/RegExp value`, [`Number startIndex`], [`Boolean anyMatch`], [`Boolean caseSensitive`] ) : Number
Finds the index of the first matching record in this store by a specific property/value.
Finds the index of the first matching record in this store by a specific property/value.
Parameters:

- `property` : String
  A property on your objects
- `value` : String/RegExp
  Either string that the property values should start with or a RegExp to test against the property.
- `startIndex` : Number
  (optional) The index to start searching at
- `anyMatch` : Boolean
  (optional) True to match any part of the string, not just the beginning
- `caseSensitive` : Boolean
  (optional) True for case sensitive comparison

Returns:

- `Number`
  The matched index or -1

Store

findBy( `Function fn`, [`Object scope`], [`Number startIndex`] ) : Number
Find the index of the first matching Record in this Store by a function. If the function returns true it is considere...
Find the index of the first matching Record in this Store by a function. If the function returns `true` it is considered a match.
Parameters:

- `fn` : Function
  The function to be called. It will be passed the following parameters:
  - record : Ext.data.Record

    The record to test for filtering. Access field values using Ext.data.Record.get.

  - id : Object

    The ID of the Record passed.

- `scope` : Object
  (optional) The scope of the function (defaults to this)
- `startIndex` : Number
  (optional) The index to start searching at

Returns:

- `Number`
  The matched index or -1

Store

fireEvent( `String eventName`, `Object... args` ) : Boolean
Fires the specified event with the passed parameters (minus the event name).
Fires the specified event with the passed parameters (minus the event name).
Parameters:

- `eventName` : String
- `args` : Object...
  Variable number of parameters are passed to handlers

Returns:

- `Boolean`
  returns false if any of the handlers return false otherwise it returns true

Observable

getAt( `Number index` ) : Ext.data.Record
Get the Record at the specified index.
Get the Record at the specified index.
Parameters:

- `index` : Number
  The index of the Record to find.

Returns:

- `Ext.data.Record`
  The Record at the passed index. Returns undefined if not found.

Store

getById( `String id` ) : Ext.data.Record
Get the Record with the specified id.
Get the Record with the specified id.
Parameters:

- `id` : String
  The id of the Record to find.

Returns:

- `Ext.data.Record`
  The Record with the passed id. Returns undefined if not found.

Store

getCount() : Number
Gets the number of cached records. If using paging, this may not be the total size of the dataset. If the data object...
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 dataset size.

Parameters:

- None.

Returns:

- `Number`
  The number of Records in the Store's cache.

Store

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

- None.

Returns:

- `Ext.data.Record[]`
  An array of Records containing outstanding modifications.

Store

getRange( [`Number startIndex`], [`Number endIndex`] ) : Ext.data.Record[]
Returns a range of Records between specified indices.
Returns a range of Records between specified indices.
Parameters:

- `startIndex` : Number
  (optional) The starting index (defaults to 0)
- `endIndex` : Number
  (optional) The ending index (defaults to the last Record in the Store)

Returns:

- `Ext.data.Record[]`
  An array of Records

Store

getSortState() : Object
Returns an object describing the current sort state of this Store.
Returns an object describing the current sort state of this Store.
Parameters:

- None.

Returns:

- `Object`
  The sort state of the Store. An object with two properties:
  - field : String

    The name of the field by which the Records are sorted.

  - direction : String

    The sort order, "ASC" or "DESC".

Store

getTotalCount() : Number
Gets the total number of records in the dataset as returned by the server. If using paging, for this to be accurate, ...
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. For remote data sources, this is provided by a query on the server.

Parameters:

- None.

Returns:

- `Number`
  The number of Records as specified in the data object passed to the Reader by the Proxy

  This value is not updated when changing the contents of the Store locally.

Store

hasListener( `String eventName` ) : Boolean
Checks to see if this object has any listeners for a specified event
Checks to see if this object has any listeners for a specified event
Parameters:

- `eventName` : String
  The name of the event to check for

Returns:

- `Boolean`
  True if the event is being listened for, else false

Observable

indexOf( `Ext.data.Record record` ) : Number
Get the index within the cache of the passed Record.
Get the index within the cache of the passed Record.
Parameters:

- `record` : Ext.data.Record
  The Ext.data.Record object to to find.

Returns:

- `Number`
  The index of the passed Record. Returns -1 if not found.

Store

indexOfId( `String id` ) : Number
Get the index within the cache of the Record with the passed id.
Get the index within the cache of the Record with the passed id.
Parameters:

- `id` : String
  The id of the Record to find.

Returns:

- `Number`
  The index of the Record. Returns -1 if not found.

Store

insert( `Number index`, `Ext.data.Record[] records` ) : void
Inserts Records to the Store at the given index and fires the add event.
Inserts Records to the Store at the given index and fires the add event.
Parameters:

- `index` : Number
  The start index at which to insert the passed Records.
- `records` : Ext.data.Record[]
  An Array of Ext.data.Record objects to add to the cache.

Returns:

- `void`

Store

isFiltered() : Boolean
Returns true if this store is currently filtered
Returns true if this store is currently filtered
Parameters:

- None.

Returns:

- `Boolean`

Store

load( `Object options` ) : void
Loads the Record cache from the configured Proxy using the configured Reader. If using remote paging, then the first ...
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 in the options.params property to establish the initial position within the dataset, 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 callback function, or in a "load" event handler.

Parameters:

- `options` : Object
  An object containing properties which control loading options:
  - params :Object

    An object containing properties to pass as HTTP parameters to a remote data source.

  - callback : Function}

    A function to be called after the Records have been loaded. The callback is passed the following arguments:

    - r : Ext.data.Record[]
    - options: Options object from the load call
    - success: Boolean success indicator
  - scope : Object

    Scope with which to call the callback (defaults to the Store object)

  - add : Boolean

    Indicator to append loaded records rather than replace the current cache.

Returns:

- `void`

Store

loadData( `Object data`, [`Boolean append`] ) : void
Loads data from a passed data block. A Reader which understands the format of the data must have been configured in t...
Loads data from a passed data block. A Reader which understands the format of the data must have been configured in the constructor.
Parameters:

- `data` : Object
  The data block from which to read the Records. The format of the data expected is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
- `append` : Boolean
  (Optional) True to append the new Records rather than replace the existing cache.

Returns:

- `void`

Store

on( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void
Appends an event handler to this element (shorthand for addListener)
Appends an event handler to this element (shorthand for addListener)
Parameters:

- `eventName` : String
  The type of event to listen for
- `handler` : Function
  The method the event invokes
- `scope` : Object
  (optional) The scope in which to execute the handler function. The handler function's "this" context.
- `options` : Object
  (optional)

Returns:

- `void`

Observable

purgeListeners() : void
Removes all listeners for this object
Removes all listeners for this object
Parameters:

- None.

Returns:

- `void`

Observable

query( `String field`, `String/RegExp value`, [`Boolean anyMatch`], [`Boolean caseSensitive`] ) : MixedCollection
Query the records by a specified property.
Query the records by a specified property.
Parameters:

- `field` : String
  A field on your records
- `value` : String/RegExp
  Either a string that the field should start with or a RegExp to test against the field
- `anyMatch` : Boolean
  (optional) True to match any part not just the beginning
- `caseSensitive` : Boolean
  (optional) True for case sensitive comparison

Returns:

- `MixedCollection`
  Returns an Ext.util.MixedCollection of the matched records

Store

queryBy( `Function fn`, [`Object scope`] ) : MixedCollection
Query the cached records in this Store using a filtering function. The specified function will be called with each re...
Query the cached records in this Store using a filtering function. The specified function will be called with each record in this Store. If the function returns `true` the record is included in the results.
Parameters:

- `fn` : Function
  The function to be called. It will be passed the following parameters:
  - record : Ext.data.Record

    The record to test for filtering. Access field values using Ext.data.Record.get.

  - id : Object

    The ID of the Record passed.

- `scope` : Object
  (optional) The scope of the function (defaults to this)

Returns:

- `MixedCollection`
  Returns an Ext.util.MixedCollection of the matched records

Store

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

- None.

Returns:

- `void`

Store

reload( [`Object options`] ) : void
Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load ope...
Reloads the Record cache from the configured Proxy using the configured Reader and the options from the last load operation performed.
Parameters:

- `options` : Object
  (optional) An object containing properties which may override the options used in the last load operation. See load for details (defaults to null, in which case the most recently used options are reused).

Returns:

- `void`

Store

remove( `Ext.data.Record record` ) : void
Remove a Record from the Store and fires the remove event.
Remove a Record from the Store and fires the remove event.
Parameters:

- `record` : Ext.data.Record
  Th Ext.data.Record object to remove from the cache.

Returns:

- `void`

Store

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

- None.

Returns:

- `void`

Store

removeListener( `String eventName`, `Function handler`, [`Object scope`] ) : void
Removes a listener
Removes a listener
Parameters:

- `eventName` : String
  The type of event to listen for
- `handler` : Function
  The handler to remove
- `scope` : Object
  (optional) The scope (this object) for the handler

Returns:

- `void`

Observable

resumeEvents() : void
Resume firing events. (see suspendEvents)
Resume firing events. (see suspendEvents)
Parameters:

- None.

Returns:

- `void`

Observable

setDefaultSort( `String fieldName`, [`String dir`] ) : void
Sets the default sort column and order to be used by the next load operation.
Sets the default sort column and order to be used by the next load operation.
Parameters:

- `fieldName` : String
  The name of the field to sort by.
- `dir` : String
  (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")

Returns:

- `void`

Store

sort( `String fieldName`, [`String dir`] ) : void
Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local...
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:

- `fieldName` : String
  The name of the field to sort by.
- `dir` : String
  (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")

Returns:

- `void`

Store

sum( `String property`, `Number start`, `Number end` ) : Number
Sums the value of property for each record between start and end and returns the result.
Sums the value of property for each record between start and end and returns the result.
Parameters:

- `property` : String
  A field on your records
- `start` : Number
  The record index to start at (defaults to 0)
- `end` : Number
  The last record index to include (defaults to length - 1)

Returns:

- `Number`
  The sum

Store

suspendEvents() : void
Suspend the firing of all events. (see resumeEvents)
Suspend the firing of all events. (see resumeEvents)
Parameters:

- None.

Returns:

- `void`

Observable

un( `String eventName`, `Function handler`, [`Object scope`] ) : void
Removes a listener (shorthand for removeListener)
Removes a listener (shorthand for removeListener)
Parameters:

- `eventName` : String
  The type of event to listen for
- `handler` : Function
  The handler to remove
- `scope` : Object
  (optional) The scope (this object) for the handler

Returns:

- `void`

Observable

## Public Events

Event | Defined By
--- | ---

add : ( `Store this`, `Ext.data.Record[] records`, `Number index` )
Fires when Records have been added to the Store
Fires when Records have been added to the Store
Listeners will be called with the following arguments:

- `this` : Store
- `records` : Ext.data.Record[]
  The array of Records added
- `index` : Number
  The index at which the record(s) were added

Store

beforeload : ( `Store this`, `Object options` )
Fires before a request is made for a new data object. If the beforeload handler returns false the load action will b...
Fires before a request is made for a new data object. If the beforeload handler returns false the load action will be canceled.
Listeners will be called with the following arguments:

- `this` : Store
- `options` : Object
  The loading options that were specified (see load for details)

Store

clear : ( `Store this` )
Fires when the data cache has been cleared.
Fires when the data cache has been cleared.
Listeners will be called with the following arguments:

- `this` : Store

Store

datachanged : ( `Store this` )
Fires when the data cache has changed, and a widget which is using this Store as a Record cache should refresh its view.
Fires when the data cache has changed, and a widget which is using this Store as a Record cache should refresh its view.
Listeners will be called with the following arguments:

- `this` : Store

Store

load : ( `Store this`, `Ext.data.Record[] records`, `Object options` )
Fires after a new set of Records has been loaded.
Fires after a new set of Records has been loaded.
Listeners will be called with the following arguments:

- `this` : Store
- `records` : Ext.data.Record[]
  The Records that were loaded
- `options` : Object
  The loading options that were specified (see load for details)

Store

loadexception : ()
Fires if an exception occurs in the Proxy during loading. Called with the signature of the Proxy's "loadexception" ev...
Fires if an exception occurs in the Proxy during loading. Called with the signature of the Proxy's "loadexception" event.
Listeners will be called with the following arguments:

- None.

Store

metachange : ( `Store this`, `Object meta` )
Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.
Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.
Listeners will be called with the following arguments:

- `this` : Store
- `meta` : Object
  The JSON metadata

Store

remove : ( `Store this`, `Ext.data.Record record`, `Number index` )
Fires when a Record has been removed from the Store
Fires when a Record has been removed from the Store
Listeners will be called with the following arguments:

- `this` : Store
- `record` : Ext.data.Record
  The Record that was removed
- `index` : Number
  The index at which the record was removed

Store

update : ( `Store this`, `Ext.data.Record record`, `String operation` )
Fires when a Record has been updated
Fires when a Record has been updated
Listeners will be called with the following arguments:

- `this` : Store
- `record` : Ext.data.Record
  The Record that was updated
- `operation` : String
  The update operation being performed. Value may be one of:

      Ext.data.Record.EDIT
       Ext.data.Record.REJECT
       Ext.data.Record.COMMIT

Store