[Reprinted] ext core API details Ext. Data (11)-store

Source: Internet
Author: User
Tags call back
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.