Ext. data. Store
Ext. data. Store
Store is a storage container that provides record objects for Ext devices. Its behavior and attributes are similar to data tables.
Method: do not list inherited methods
Store (Object config)
Constructor. config is defined ...{
AutoLoad: Boolean/Object, // automatically load
BaseParams: Object, // meaningful only when httpproxy is used
Data: Array, // data
Proxy: Ext. data. DataProxy, // data proxy
PruneModifiedRecords: boolean, // clear the modification Information
Reader: Ext. data. Reader, // data reader
RemoteSort: boolean, // remote sorting?
SortInfo: Object, // {field: "fieldName", direction: "ASC | DESC "}
Url: String, // construct HttpProxy using url
}
Add (Ext. data. Record [] records): void
Add records to store
AddSorted (Ext. data. Record record): void
Add record to store and sort (only available for local sorting)
ClearFilter (Boolean suppressEvent): void
Clear Filter
Collect (String dataIndex, [Boolean allowNull], [Boolean bypassFilter]): Array
Collects the unique values of fields specified by dataIndex.
CommitChanges (): void
Submitting all changes to the Store will trigger an Update event.
Filter (String field, String/RegExp value, [Boolean anyMatch], [Boolean caseSensitive]): void
Set Filter
Field: String // field name
Value: String // If RegExp is a character generator, check whether the field starts with value. If it is a regular expression, check whether the field matches.
AnyMatch: Boolean // matches any part, not only the start
CaseSensitive: Boolean // case sensitive?
FilterBy (Function fn, [Object scope]): void
More powerful filtering method. fn receives two parameters record and id
Find (String property, String/RegExp value, [Number startIndex], [Boolean anyMatch], [Boolean caseSensitive]): Number
Find the first record that meets the condition. The parameter is the same as that of filter.
FindBy (Function fn, [Object scope], [Number startIndex]): Number
See filterBy
GetAt (Number index): Ext. data. Record
GetById (String id): Ext. data. Record
Obtain the record object based on the filling number/id.
GetCount (): void
Number of records obtained
GetModifiedRecords (): Ext. data. Record []
Get the modified record set
GetRange ([Number startIndex], [Number endIndex]): Ext. data. Record []
Obtains the set of records within the specified range.
GetSortState (): void
Get the sorting status: it is obviously not void but returns a sorting object, with the same structure as sortInfo... {field: "fieldName", direction: "ASC | DESC "}
GetTotalCount (): void
This is useful for paging information.
IndexOf (Ext. data. Record record): Number
IndexOfId (String id): Number
Obtain the serial number from the record or id
Insert (Number index, Ext. data. Record [] records): void
Inserts records at the specified position and triggers the add event.
IsFiltered (): Boolean
If a filter is set, the returned result is true.
Load (Object options): void
The specified Proxy uses the specified reader to read remote data.
Options is defined
...{
Params: Object, // parameters to be attached to the request url
Callback: Function // call back method, which receives three parameters
// R: Ext. data. Record [] // returned record Array
// Options: Options imported by the options load Method
// Success: Boolean // success
Scope: Object, // range. The default value is store.
Add: Boolean append or update
}
LoadData (Object data, [Boolean append]): void
It is easier to use than load for the same purpose, but the data is read locally.
Query (String field, String/RegExp value, [Boolean anyMatch], [Boolean caseSensitive]): MixedCollection
QueryBy (Function fn, [Object scope]): MixedCollection
Query. The parameters are similar to find, but all matching records are returned, instead of the sequence number of the first matching record.
RejectChanges (): void
Discard all changes
Reload ([Object options]): void
Re-load is equivalent to load (options, false). If no options is input, take the parameter used in the last load.
Remove (Ext. data. Record record): void
Remove a specified record
RemoveAll (): void
Remove all records
SetDefaultSort (String fieldName, [String dir]): void
Set Default sorting rules
Sort (String fieldName, [String dir]): void
Sort
Sum (String property, Number start, Number end): Number
Sum the property field from start to end
Event list
Add: (Store this, Ext. data. Record [] records, Number index)
Beforeload: (Store this, Object options)
Clear: (Store this)
Datachanged: (Store this)
Load: (Store this, Ext. data. Record [] records, Object options)
Loadexception :()
Metachange: (Store this, Object meta)
Remove: (Store this, Ext. data. Record record, Number index)
Update: (Store this, Ext. data. Record record, String operation)
It is easy to look at the name, and the parameters are not complex.
Use Cases
// Obtain the remote json object
// The content of jsoncallback. js is
// {'Results': 2, 'rows ':[
// {'Id': 1, 'name': 'Bill ', occupation: 'gardener '},
// {'Id': 2, 'name': 'ben', occupation: 'horticulturalist'}]
//}
// Define proxy
Var proxy = new Ext. data. HttpProxy (... {url: 'jsoncallback. js '});
// Define reader
Var reader = new Ext. data. JsonReader (
......{
TotalProperty: "results", // The totalRecords property is obtained by json. results.
Root: "rows", // The array for constructing metadata is obtained by json. rows.
Id: "id" // id is obtained by json. id
},[
... {Name: 'name', mapping: 'name '},
... {Name: 'occupation'} // if the name and mapping have the same name, you can omit mapping.
]
)
// Create a Store
Var store = new Ext. data. Store (......{
Proxy: proxy,
Reader: reader
});
// Load
Store. load ();
Example 2
// Obtain the remote xml file
// The content of the xml file is
<? Xml version = "1.0" encoding = "UTF-8"?>
<Dataset>
<Results> 2 </results>
<Row>
<Id> 1 </id>
<Name> Bill </name>
<Occupation> Gardener </occupation>
</Row>
<Row>
<Id> 2 </id>
<Name> Ben </name>
<Occupation> Horticulturalist </occupation>
</Row>
</Dataset>
Var proxy = new Ext. data. HttpProxy (... {url: 'datasource. xml '});
Var reader = new Ext. data. XmlReader (......{
TotalRecords: "results ",
Record: "row ",
Id: "id"
},[
... {Name: 'name', mapping: 'name '},
... {Name: 'occupation '}
]);
Var store = new Ext. data. Store (......{
Proxy: proxy,
Reader: reader
});
Store. load ();
Example 3
// Obtain from the local Array
Var arr = [[1, 'bill ', 'gardener'], [2, 'ben', 'horticulturalist'];
Var reader = new Ext. data. ArrayReader (
... {Id: 0 },
[
... {Name: 'name', mapping: 1 },
... {Name: 'occupation', mapping: 2}
]);
Var store = new Ext. data. Store (......{
Reader: reader
});
Store. loadData (arr );