PDA

View Full Version : MVC: Iterate through Store in Grid Panel



voodoov
18 Mar 2012, 11:23 AM
Hi,

I want to get the Store from Grid so I can iterate through it, but when I use getStore() method, it returns only String Name of my Store. These are my codes:

Users.js (Store)

Ext.define('MyApp.store.Users', {
extend: 'Ext.data.Store',

model: 'MyApp.model.User',
autoLoad: true,

proxy: {
type: 'ajax',
api: {
read: 'data/data.json'
},
reader: {
type: 'json',
root: 'UserInfo["User-1"]'
}
}
});

User.js (Model)

Ext.define('MyApp.model.User', {
extend: 'Ext.data.Model',

fields: ['0','1','2','3','4','5']
});

UserList.js (View)

Ext.define('MyApp.view.UserList' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.userlist',

store: 'Users',

initComponent: function() {

var store = this.getStore(); // store = 'Users' (?)

this.columns = [
{header: 'A', dataIndex: '0', flex: 1},
{header: 'B', dataIndex: '1', flex: 1},
{header: 'C', dataIndex: '2', flex: 1},
{header: 'D', dataIndex: '3', flex: 1},
{header: 'E', dataIndex: '4', flex: 1}
];

this.callParent(arguments);
}
});

The grid is showing data without problem, but I don't know how to get Store from it?

Thank you in Advance.

mankz
18 Mar 2012, 1:10 PM
Call getStore() after callParent(arguments). Or look it up using StoreMgr manually...

voodoov
18 Mar 2012, 9:10 PM
Thank you mankz,
It works now. And I got what happens here...

But why the store is empty?
I have 3 rows of data in my Grid now.


...

this.callParent(arguments);

var store = this.getStore(); // store = Store Object ( Empty )
var count = store.getCount(); // count = 0
debugger;

Thank you for your support.