PDA

View Full Version : Dynamic grids



romykm
25 Apr 2012, 2:58 AM
Hello. I would like to prepare the grid component in our project. I want to use this grid with respect to used store and connected model. It means columns of the grid should be constructed according to model fields.


Ext.application( {
name: 'UserManagement',
launch: function() {
Ext.create( 'Ext.container.Viewport', {
layout: 'fit',
items: [
Ext.create( 'My.grid', {
store: this.getController( 'My.Apps.user.controllers.Users' ).getStore('My.Apps.user.stores.Users' )
} )
]
} );
},

controllers: [ 'My.Apps.user.controllers.Users' ]
} );

Store:

Ext.define( 'My.Apps.user.stores.Users', {
extend: 'Ext.data.Store',
model: 'My.Apps.user.models.User',
autoLoad: true
} );

Model:

Ext.define( 'My.Apps.user.models.User', {
extend: 'Ext.data.Model',
fields: [
{
useNull: true,
name: 'id',
type: 'integer',
required: true,
label: 'Id'
},
{
name: 'firstName',
type: 'short-string',
required: true,
label: 'First Name'
}
]
} );

In the grid we need to find what fields are defined in the model. We have this.store.


var entityItems = this.store.model.fields.items;// Doesn't work

How to find what fields are used in the model? I am able to do this.store.model.prototype.fields.items; but it doesn't seems to be right way. Is it suitable to solve this kind of problem by prototype? Thank you.

scottmartin
25 Apr 2012, 9:53 AM
See if this post helps:
http://www.sencha.com/forum/showthread.php?196701

Regards,
Scott.