Clear Up
SharpKit Reference

Store Class

Namespace: Ext.data

Base Types

System.Object

Constructors

Name Description
Store()
Store(StoreConfig)
Store(object) Creates the store. @param {Object} config (optional) Config object

Methods

Name Description
add(object) Adds Model instance to the Store. This method accepts either: * - An array of Model instances or Model configuration objects. - Any number of Model instance or Model configuration object arguments. * The new Model instances will be added at the end of the existing collection. * Sample usage: * myStore.add({some: 'data'}, {some: 'other data'}); * @param {Ext.data.Model[]/Ext.data.Model...} model An array of Model instances or Model configuration objects, or variable number of Model instance or config arguments. @return {Ext.data.Model[]} The model instances that were added
aggregate(JsAction, object, bool, JsArray) Runs the aggregate function for all the records in the store. @param {Function} fn The function to execute. The function is called with a single parameter, an array of records for that group. @param {Object} scope (optional) The scope to execute the function in. Defaults to the store. @param {Boolean} grouped (Optional) True to perform the operation for each group in the store. The value returned will be an object literal with the key being the group name and the group average being the value. The grouped parameter is only honored if the store has a groupField. @param {Array} args (optional) Any arguments to append to the function call @return {Object} An object literal with the group names and their appropriate values.
average(JsString, bool) Gets the average value in the store. @param {String} field The field in each record @param {Boolean} grouped (Optional) True to perform the operation for each group in the store. The value returned will be an object literal with the key being the group name and the group average being the value. The grouped parameter is only honored if the store has a groupField. @return {Object} The average value, if no items exist, 0.
cacheRecords(object, Operation) Caches the records in the prefetch and stripes them with their server-side index. @private @param {Ext.data.Model[]} records The records to cache @param {Ext.data.Operation} The associated operation
clearData()
clearFilter(bool) Revert to a view of the Record cache with no filtering applied. @param {Boolean} suppressEvent If true the filter is cleared silently without firing the {@link #datachanged} event.
clearGrouping() Clear any groupers in the store
collect(JsString, bool, bool) Collects unique values for a particular dataIndex from this store. @param {String} dataIndex The property to collect @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered @return {Object[]} An array of the unique values
count(bool) Gets the count of items in the store. @param {Boolean} grouped (Optional) True to perform the operation for each group in the store. The value returned will be an object literal with the key being the group name and the count for each group being the value. The grouped parameter is only honored if the store has a groupField. @return {Number} the count
createFilterFn(JsString, object, bool, bool, bool) @private Returns a filter function used to test a the given property's value. Defers most of the work to Ext.util.MixedCollection's createValueMatcher function @param {String} property The property to create the filter function for @param {String/RegExp} value The string/regex to compare the property value to @param {Boolean} anyMatch True if we don't care if the filter value is not the full value (defaults to false) @param {Boolean} caseSensitive True to create a case-sensitive regex (defaults to false) @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
createModel(object) Converts a literal to a model, if it's not a model already @private @param record {Ext.data.Model/Object} The record to create @return {Ext.data.Model}
decodeGroupers(object) @private Normalizes an array of grouper objects, ensuring that they are all Ext.util.Grouper instances @param {Object[]} groupers The groupers array @return {Ext.util.Grouper[]} Array of Ext.util.Grouper objects
doSort(object)
each(JsAction, object) Calls the specified function for each of the {@link Ext.data.Model Records} in the cache. @param {Function} fn The function to call. The {@link Ext.data.Model Record} is passed as the first parameter. Returning false aborts and exits the iteration. @param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to the current {@link Ext.data.Model Record} in the iteration.
filter(object, JsString) Filters the loaded set of records by a given set of filters. * Filtering by single field: * store.filter("email", /\.com$/); * Using multiple filters: * store.filter([ {property: "email", value: /\.com$/}, {filterFn: function(item) { return item.get("age") > 10; }} ]); * Using Ext.util.Filter instances instead of config objects (note that we need to specify the {@link Ext.util.Filter#root root} config option in this case): * store.filter([ Ext.create('Ext.util.Filter', {property: "email", value: /\.com$/, root: 'data'}), Ext.create('Ext.util.Filter', {filterFn: function(item) { return item.get("age") > 10; }, root: 'data'}) ]); * @param {Object[]/Ext.util.Filter[]/String} filters The set of filters to apply to the data. These are stored internally on the store, but the filtering itself is done on the Store's {@link Ext.util.MixedCollection MixedCollection}. See MixedCollection's {@link Ext.util.MixedCollection#filter filter} method for filter syntax. Alternatively, pass in a property string @param {String} value (optional) value to filter by (only if using a property string as the first argument)
filterBy(JsAction, object) 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. @param {Function} fn The function to be called. It will be passed the following parameters:
  • record : Ext.data.Model

    The {@link Ext.data.Model record} to test for filtering. Access field values using {@link Ext.data.Model#get}.

  • id : Object

    The ID of the Record passed.

@param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to this Store.
find(JsString, object, JsNumber, bool, bool, bool) Finds the index of the first matching Record in this store by a specific field value. @param {String} fieldName The name of the Record field to test. @param {String/RegExp} value Either a string that the field value should begin with, or a RegExp to test against the field. @param {Number} startIndex (optional) The index to start searching at @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning @param {Boolean} caseSensitive (optional) True for case sensitive comparison @param {Boolean} exactMatch (optional) True to force exact match (^ and $ characters added to the regex). Defaults to false. @return {Number} The matched index or -1
findBy(JsAction, object, JsNumber) Find the index of the first matching Record in this Store by a function. If the function returns true it is considered a match. @param {Function} fn The function to be called. It will be passed the following parameters:
  • record : Ext.data.Model

    The {@link Ext.data.Model record} to test for filtering. Access field values using {@link Ext.data.Model#get}.

  • id : Object

    The ID of the Record passed.

@param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to this Store. @param {Number} startIndex (optional) The index to start searching at @return {Number} The matched index or -1
findExact(JsString, object, JsNumber) Finds the index of the first matching Record in this store by a specific field value. @param {String} fieldName The name of the Record field to test. @param {Object} value The value to match the field against. @param {Number} startIndex (optional) The index to start searching at @return {Number} The matched index or -1
findRecord() Finds the first matching Record in this store by a specific field value. @param {String} fieldName The name of the Record field to test. @param {String/RegExp} value Either a string that the field value should begin with, or a RegExp to test against the field. @param {Number} startIndex (optional) The index to start searching at @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning @param {Boolean} caseSensitive (optional) True for case sensitive comparison @param {Boolean} exactMatch (optional) True to force exact match (^ and $ characters added to the regex). Defaults to false. @return {Ext.data.Model} The matched record or null
fireGroupChange() Fires the groupchange event. Abstracted out so we can use it as a callback @private
first(bool) Convenience function for getting the first model instance in the store @param {Boolean} grouped (Optional) True to perform the operation for each group in the store. The value returned will be an object literal with the key being the group name and the first record being the value. The grouped parameter is only honored if the store has a groupField. @return {Ext.data.Model/undefined} The first model instance in the store, or undefined
getAt(JsNumber) Get the Record at the specified index. @param {Number} index The index of the Record to find. @return {Ext.data.Model} The Record at the passed index. Returns undefined if not found.
getAverage(object, object)
getById(JsString) Get the Record with the specified id. @param {String} id The id of the Record to find. @return {Ext.data.Model} The Record with the passed id. Returns undefined if not found.
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 {@link #getTotalCount} function returns the dataset size. Note: see the Important note in {@link #load}.

@return {Number} The number of Records in the Store's cache.
getGroupData(bool) @private

Returns records grouped by the configured {@link #groupers grouper} configuration. Sample return value (in this case grouping by genre and then author in a fictional books dataset):

  
[
{
name: 'Fantasy',
depth: 0,
records: [
//book1, book2, book3, book4
],
children: [
{
name: 'Rowling',
depth: 1,
records: [
//book1, book2
]
},
{
name: 'Tolkein',
depth: 1,
records: [
//book3, book4
]
}
]
}
]
            
@param {Boolean} sort True to call {@link #sort} before finding groups. Sorting is required to make grouping function correctly so this should only be set to false if the Store is known to already be sorted correctly (defaults to true) @return {Object[]} The group data
getGroups(JsString) Returns an array containing the result of applying grouping to the records in this store. See {@link #groupField}, {@link #groupDir} and {@link #getGroupString}. Example for a store containing records with a color field:
  
var myStore = Ext.create('Ext.data.Store', {
groupField: 'color',
groupDir  : 'DESC'
});
myStore.getGroups(); //returns:
[
{
name: 'yellow',
children: [
//all records where the color field is 'yellow'
]
},
{
name: 'red',
children: [
//all records where the color field is 'red'
]
}
]
            
@param {String} groupName (Optional) Pass in an optional groupName argument to access a specific group as defined by {@link #getGroupString} @return {Object/Object[]} The grouped data
getGroupsForGrouper(object, object) @private For a given set of records and a Grouper, returns an array of arrays - each of which is the set of records matching a certain group.
getGroupsForGrouperIndex(object, JsNumber) @private This is used recursively to gather the records into the configured Groupers. The data MUST have been sorted for this to work properly (see {@link #getGroupData} and {@link #getGroupsForGrouper}) Most of the work is done by {@link #getGroupsForGrouper} - this function largely just handles the recursion. @param {Ext.data.Model[]} records The set or subset of records to group @param {Number} grouperIndex The grouper index to retrieve @return {Object[]} The grouped records
getGroupString(Model)

Returns the string to group on for a given model instance. The default implementation of this method returns the model's {@link #groupField}, but this can be overridden to group by an arbitrary string. For example, to group by the first letter of a model's 'name' field, use the following code:

  
Ext.create('Ext.data.Store', {
groupDir: 'ASC',
getGroupString: function(instance) {
return instance.get('name')[0];
}
});
            
@param {Ext.data.Model} instance The model instance @return {String} The string to compare when forming groups
getMax(object, object)
getMin(object, object)
getNewRecords()
getPageFromRecordIndex(JsNumber) Determines the page from a record index @param {Number} index The record index @return {Number} The page the record belongs to
getRange(JsNumber, JsNumber) Returns a range of Records between specified indices. @param {Number} startIndex (optional) The starting index (defaults to 0) @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store) @return {Ext.data.Model[]} An array of Records
getRequestId() Returns a unique requestId to track requests. @private
getSum(object, object)
getTotalCount() Returns the total number of {@link Ext.data.Model Model} instances that the {@link Ext.data.proxy.Proxy Proxy} indicates exist. This will usually differ from {@link #getCount} when using paging - getCount returns the number of records loaded into the Store at the moment, getTotalCount returns the number of records that could be loaded into the Store if the Store contained all data @return {Number} The total number of Model instances available via the Proxy
getUpdatedRecords()
group(object, JsString) Group data in the store @param {String/Object[]} groupers Either a string name of one of the fields in this Store's configured {@link Ext.data.Model Model}, or an Array of grouper configurations. @param {String} direction The overall direction to group the data by. Defaults to "ASC".
guaranteeRange(object, object, object, object) Guarantee a specific range, this will load the store with a range (that must be the pageSize or smaller) and take care of any loading that may be necessary.
hasPendingRequests() Returns the number of pending requests out.
indexOf(Model) Get the index within the cache of the passed Record. @param {Ext.data.Model} record The Ext.data.Model object to find. @return {Number} The index of the passed Record. Returns -1 if not found.
indexOfId(JsString) Get the index within the cache of the Record with the passed id. @param {String} id The id of the Record to find. @return {Number} The index of the Record. Returns -1 if not found.
indexOfTotal(Model) Get the index within the entire dataset. From 0 to the totalCount. @param {Ext.data.Model} record The Ext.data.Model object to find. @return {Number} The index of the passed Record. Returns -1 if not found.
insert(JsNumber, object) Inserts Model instances into the Store at the given index and fires the {@link #add} event. See also
{@link #add}
. @param {Number} index The start index at which to insert the passed Records. @param {Ext.data.Model[]} records An Array of Ext.data.Model objects to add to the cache.
isFiltered() Returns true if this store is currently filtered @return {Boolean}
isGrouped() Checks if the store is currently grouped @return {Boolean} True if the store is grouped.
last(bool) Convenience function for getting the last model instance in the store @param {Boolean} grouped (Optional) True to perform the operation for each group in the store. The value returned will be an object literal with the key being the group name and the last record being the value. The grouped parameter is only honored if the store has a groupField. @return {Ext.data.Model/undefined} The last model instance in the store, or undefined
load(object)

Loads data into the Store via the configured {@link #proxy}. This uses the Proxy to make an asynchronous call to whatever storage backend the Proxy uses, automatically adding the retrieved instances into the Store and calling an optional callback if required. Example usage:

*
  
store.load({
scope   : this,
callback: function(records, operation, success) {
//the {@link Ext.data.Operation operation} object contains all of the details of the load operation
console.log(records);
}
});
            
*

If the callback scope does not need to be set, a function can simply be passed:

*
  
store.load(function(records, operation, success) {
console.log('loaded records');
});
            
* @param {Object/Function} options (Optional) config object, passed into the Ext.data.Operation object before loading.
loadData(object, bool) Loads an array of data straight into the Store @param {Ext.data.Model[]/Object[]} data Array of data to load. Any non-model instances will be cast into model instances first @param {Boolean} append True to add the records to the existing records in the store, false to remove the old ones first
loadPage(JsNumber, object) Loads a given 'page' of data by setting the start and limit values appropriately. Internally this just causes a normal load operation, passing in calculated 'start' and 'limit' params @param {Number} page The number of the page to load @param {Object} options See options for {@link #load}
loadRecords(object, object) Loads an array of {@Ext.data.Model model} instances into the store, fires the datachanged event. This should only usually be called internally when loading from the {@link Ext.data.proxy.Proxy Proxy}, when adding records manually use {@link #add} instead @param {Ext.data.Model[]} records The array of records to load @param {Object} options {addRecords: true} to add these records to the existing records, false to remove the Store's existing records first
mask()
max(JsString, bool) Gets the maximum value in the store. @param {String} field The field in each record @param {Boolean} grouped (Optional) True to perform the operation for each group in the store. The value returned will be an object literal with the key being the group name and the maximum in the group being the value. The grouped parameter is only honored if the store has a groupField. @return {Object} The maximum value, if no items exist, undefined.
min(JsString, bool) Gets the minimum value in the store. @param {String} field The field in each record @param {Boolean} grouped (Optional) True to perform the operation for each group in the store. The value returned will be an object literal with the key being the group name and the minimum in the group being the value. The grouped parameter is only honored if the store has a groupField. @return {Object} The minimum value, if no items exist, undefined.
nextPage(object) Loads the next 'page' in the current data set @param {Object} options See options for {@link #load}
onBeforeSort()
onClassExtended(object, object, object)
onCreateRecords(object, Operation, bool) Create any new records when a write is returned from the server. @private @param {Ext.data.Model[]} records The array of new records @param {Ext.data.Operation} operation The operation that just completed @param {Boolean} success True if the operation was successful
onDestroyRecords(object, Operation, bool) Remove any records when a write is returned from the server. @private @param {Ext.data.Model[]} records The array of removed records @param {Ext.data.Operation} operation The operation that just completed @param {Boolean} success True if the operation was successful
onGuaranteedRange() Handles a guaranteed range being loaded @private
onProxyLoad(object) @private Called internally when a Proxy has completed a load request
onProxyPrefetch(Operation) Called after the configured proxy completes a prefetch operation. @private @param {Ext.data.Operation} operation The operation that completed
onUpdateRecords(object, Operation, bool) Update any records when a write is returned from the server. @private @param {Ext.data.Model[]} records The array of updated records @param {Ext.data.Operation} operation The operation that just completed @param {Boolean} success True if the operation was successful
onWaitForGuarantee()
prefetch(object) Prefetches data into the store using its configured {@link #proxy}. @param {Object} options (Optional) config object, passed into the Ext.data.Operation object before loading. See {@link #load}
prefetchPage(JsNumber, object) Prefetches a page of data. @param {Number} page The page to prefetch @param {Object} options (Optional) config object, passed into the Ext.data.Operation object before loading. See {@link #load}
previousPage(object) Loads the previous 'page' in the current data set @param {Object} options See options for {@link #load}
purgeRecords() Purge the least recently used records in the prefetch if the purgeCount has been exceeded.
queryBy(JsAction, object) 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. @param {Function} fn The function to be called. It will be passed the following parameters:
  • record : Ext.data.Model

    The {@link Ext.data.Model record} to test for filtering. Access field values using {@link Ext.data.Model#get}.

  • id : Object

    The ID of the Record passed.

@param {Object} scope (optional) The scope (
this
reference) in which the function is executed. Defaults to this Store. @return {Ext.util.MixedCollection} Returns an Ext.util.MixedCollection of the matched records
rangeSatisfied(JsNumber, JsNumber) Determines if the range has already been satisfied in the prefetchData. @private @param {Number} start The start index @param {Number} end The end index in the range
remove(object, object) private
removeAll(bool) Remove all items from the store. @param {Boolean} silent Prevent the `clear` event from being fired.
removeAt(JsNumber) Removes the model instance at the given index @param {Number} index The record index
sort()
sum(JsString, bool) Sums the value of property for each {@link Ext.data.Model record} between start and end and returns the result. @param {String} field A field in each record @param {Boolean} grouped (Optional) True to perform the operation for each group in the store. The value returned will be an object literal with the key being the group name and the sum for that group being the value. The grouped parameter is only honored if the store has a groupField. @return {Number} The sum
unmask()

Properties

Name Description
alias
buffered @cfg {Boolean} buffered Allow the store to buffer and pre-fetch pages of records. This is to be used in conjunction with a view will tell the store to pre-fetch records ahead of a time.
clearOnPageLoad @cfg {Boolean} clearOnPageLoad True to empty the store when loading another page via {@link #loadPage}, {@link #nextPage} or {@link #previousPage} (defaults to true). Setting to false keeps existing records, allowing large data sets to be loaded one page at a time but rendered all together.
Count 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 {@link #getTotalCount} function returns the dataset size. Note: see the Important note in {@link #load}.

@return {Number} The number of Records in the Store's cache.
currentPage The page that the Store has most recently loaded (see {@link #loadPage}) @property currentPage @type Number
extend
groupDir The direction in which sorting should be applied when grouping. Defaults to "ASC" - the other supported value is "DESC" @property groupDir @type String
isStore @cfg {Number} purgePageCount The number of pages to keep in the cache before purging additional records. A value of 0 indicates to never purge the prefetched data. This option is only relevant when the {@link #buffered} option is set to true.
loading True if the Store is currently loading via its Proxy @property loading @type Boolean @private
pageSize @cfg {Number} pageSize The number of records considered to form a 'page'. This is used to power the built-in paging using the nextPage and previousPage functions. Defaults to 25.
purgePageCount @cfg {Number} purgePageCount The number of pages to keep in the cache before purging additional records. A value of 0 indicates to never purge the prefetched data. This option is only relevant when the {@link #buffered} option is set to true.
remoteFilter @cfg {Boolean} remoteFilter True to defer any filtering operation to the server. If false, filtering is done locally on the client. Defaults to false.
remoteGroup @cfg {Boolean} remoteGroup True if the grouping should apply on the server side, false if it is local only (defaults to false). If the grouping is local, it can be applied immediately to the data. If it is remote, then it will simply act as a helper, automatically sending the grouping information to the server.
remoteSort @cfg {Boolean} remoteSort True to defer any sorting operation to the server. If false, sorting is done locally on the client. Defaults to false.
sortOnFilter @cfg {Boolean} sortOnFilter For local filtering only, causes {@link #sort} to be called whenever {@link #filter} is called, causing the sorters to be reapplied after filtering. Defaults to true
TotalCount Returns the total number of {@link Ext.data.Model Model} instances that the {@link Ext.data.proxy.Proxy Proxy} indicates exist. This will usually differ from {@link #getCount} when using paging - getCount returns the number of records loaded into the Store at the moment, getTotalCount returns the number of records that could be loaded into the Store if the Store contained all data @return {Number} The total number of Model instances available via the Proxy
© Copyright 2005-2011 SharpKit. All rights reserved.