View Full Version : need help with loading data into a template from a data store

10 Aug 2010, 6:52 AM
i have been trying to link data from a data store to a template in a panel (not grid) in vain and i would like to know how it is done. the manual that comes with the designer doesn't explain it exhaustively.
thank you.

10 Aug 2010, 7:43 AM
Hi 720,

A Template or XTemplate (the latter is much more powerful) will simply accept an array or object of data. It doesn't bind itself to a store and retrieve that data, so you need to pull the data out of the store and feed it to the template. As far as Design time support for this, there is none at this time, but we are looking to implementing a Template Manager in the near future.

Here is an example of how to get the data out and feed it to your template in your implementation:

var store = new Ext.data.JsonStore({
storeId: 'Names',
url: 'names.json',
autoLoad: true,
fields: ['first_name', 'last_name']

// If your store has a storeId and you want to retrieve it using that...
var storeById = Ext.StoreMgr.lookup('Names');

var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<tpl for="data">',
'<div>{first_name} {last_name}</div>',

var html = tpl.apply(store.getRange());

You can get all of the Records out of a Store by calling its getRange() method without any parameters. A Record has a "data" property which is a basic object. We interrogate that property for each Record in the template and write out the first_name and last_name fields.

Let me know if that makes sense or if you have any more questions regarding that scenario. Thanks.