PDA

View Full Version : multiple instances of store in controller



jaggernat
31 Oct 2014, 2:38 PM
hi experts


I am trying to instantiate a grid component in my accordion


In my controller i am doing




Ext.each(Items, function(Item, index) {
Ext.Ajax.request({
loadMask : true,
url : 'getByNew.controller',
method : 'GET',
params: {
Id: Id,


},
scope : this,
success : function(response, callOptions) {
var Data = Ext.decode(response.responseText);


accordian.add({

title:Data.id

items: [
{

layout: {
type: 'hbox',
pack : 'center'
},
items:[{

initComponent : function(){
debugger;
var me = this;
var tpainStore = Ext.create('TPAIN.store.MyStore');
Ext.apply(me,{
store: tpainStore
});
me.callParent(arguments);
},

xtype: 'grid',
id : 'tod'+index,
alias: 'widget.tod'+index,
title: 'Product',
height : 400,
width : 420,
stripeRows : true,
columnLines: true,
//store:
margin : '3 3 3 3',
columns: [
{header: 'Product', dataIndex: 'product', flex: 1,sortable:true,hideable:false}
]

}




In my initComponent i am trying to instatiate store each time and it doesnt work ,
When i run the app i get error : Uncaught TypeError: Cannot read property 'items' of undefined

If i remove the initComponent function it works fine.

Any idea how i can do this?
Any help will be appreciated


Thanks
Jay

scottmartin
1 Nov 2014, 1:20 PM
When you create a store, define an alias. Then in your view, create a new instance of the store by using type



Ext.define('MyStore', {
extend: 'Ext.data.Store',

alias: 'store.mystore',




Ext.create('Ext.grid.Panel', {
title: 'Simpsons',

store: {
type: 'mystore'
},

jaggernat
3 Nov 2014, 5:03 AM
Yep, That works.Thanks.