Sencha: Working With Data Stores in Designer
Sencha: Working With Data Stores in Designer
Sencha, Inc.
www.sencha.com
525 University Avenue, Suite 23
Palo Alto, CA 94301
Contents
What is a Data Store? .............................................................................................................1
Using Data Stores in Designer.................................................................................................. 1
Choosing a Store Type....................................................................................................... 1
Cross-Domain Requests................................................................................................ 2
Specifying the Location of the Source Data........................................................................... 2
Mapping Data Fields.......................................................................................................... 4
Loading Data into a Store................................................................................................... 5
Binding a Store to a UI Component ..................................................................................... 6
Examples.............................................................................................................................. 7
Using a Json Store............................................................................................................. 7
Using an XML Store .......................................................................................................... 8
Using an Array Store .........................................................................................................9
Cross-Domain Requests
It's important to note that an HTTPProxy can only retrieve data from within the same domain. This
means that you cannot create a Json Store or XML Store to get data from a remote source. For cross-
domain requests, you have to use a ScriptTagProxy.
A JsonP Store type that uses ScriptTagProxy to access Json packets will be provided in Designer to
facilitate cross-domain requests.
2
To specify the location of the source data for a Store:
1. Select the Store in the Data Stores tab.
2. Set the Store's url attribute to point to the source data.
3. For most Store types, you also need to set the root attribute to tell the reader the name of the
property from which to read the data.
Mapping Data Fields
You need to add a field to your Store for each element you want to load from the source.
To add fields to your Store:
1. Right-click the store in the Data Stores tab.
2. Select Add Fields and the number of fields you want to add to the store.
By default, each field in your data source is mapped to field of the same name in the source data.
However, you can map a field to any arbitrary source field by specifying the mapping attribute in the
field configuration. For example, you might want to drop underscores, change the capitalization from
the way it appears in the source data, or map to a field with a completely different name.
To map a field to a source field of a different name:
1. Select the field in the Data Stores tab.
2. Set the field's mapping attribute to identify the source data you want to map to the field.
You can also control how the data read from a source field is formatted. For example, to specify how
you want to display the contents of a date field, you specify the dateFormat attribute in the field
configuration. This is a PHP-style date formatting string, for more information see Date.
Similarly, you can set the sortType attribute to control how the field is treated when sorting. You
specify one of the predefined SortType functions, or a define and use a custom sort function.
3. Configure the component to use the data from the store. This varies depending on the type of
component. For example, for a DataGrid you set the dataIndex of each column to the field
that you want to display. Note that the data is displayed immediately when you set the
dataIndex.
For a ComboBox, you specify the itemId and name attributes to correspond to the appropriate
fields in your Data Store.
The data should display immediately in the UI component. If it doesn't:
Make sure you can load the store. The most common problem is incorrectly specifying the
path to the store.
Check your Data Store configuration. Have you defined the fields you're trying to display? If
needed, is the root specified correctly?
Check the component configuration. Have you correctly specified which fields you want to
display?
Note: Currently, data from a connected store is not displayed in the Designer's Preview mode. To see
how the data displays within a web page, export your project and access it through your Web browser.
Examples
The following examples show how to create a Data Store in Designer and connect it to various types of
source data.