PDA

View Full Version : Store with new params by View



Alex_Dutch
26 Apr 2013, 10:04 AM
Hi.
I've create a tab panel and each tab is a category.
For each tab I've create a widget view, for manipulate store, columns.


Ext.define('UserApp.view.goods.scoList' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.Sco',
id: 'Idsco',
store: 'User',
title : 'Sco',
dockedItems: [{
xtype: 'pagingtoolbar',
store: 'User',
dock: 'bottom',
displayInfo: true
}],
initComponent: function() {

this.columns = [
{header: 'Model', dataIndex: 'goods', flex: 1},
{header: 'Quantity', dataIndex: 'quantity', flex: 1},
{header: 'Year', dataIndex: 'year', flex: 1},
{header: 'Color', dataIndex: 'color', flex: 1},
{header: 'Comments', dataIndex: 'comments', flex: 1}
];

this.callParent(arguments);
}
});


I have one store, that have all categories:


Ext.define('UserApp.store.User', {
extend: 'Ext.data.Store',
model: 'UserApp.model.User',
autoLoad: true,
pageSize: 10,
proxy: {
type: 'ajax',
api: {
read: 'data/readGoods.php',
update: 'data/updateGoods.php',
create: 'data/createGoods.php',
destroy: 'data/deleteGoods.php'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
},
writer: {
type: 'json',
root: 'data',
encode: true
}
}
});


Model:


Ext.define('UserApp.model.User', {
extend: 'Ext.data.Model',
idProperty: 'goodsId',
fields: ['goodsId', 'quantity', 'year', 'color', 'comments', 'goods', 'category']
});


Main viewport, some code:


...
items: [{
title: 'List of goods',
xtype: 'tabpanel',
items: [{
xtype: 'Sco',
title: 'Snow'
},{
xtype: 'Scm',
title: 'Scot'
},{
...
}]

},
...


The question is - how in a view specify parameters for store, that get required category.
May be I need use a baseParams or extraParams...

Thanks in advance.

Alex_Dutch
27 Apr 2013, 12:03 PM
In another words.
On each tab get different category of goods from one store and one model.

Maybe I need set a filter, params, ... or reconfig store for each tab.


Do I really need to create a different stores for all tabs?

slemmon
29 Apr 2013, 3:32 PM
What you can do is define the store and give it an alias of store.alias like this:



Ext.define('UserApp.store.User', {
extend: 'Ext.data.Store',
alias: 'store.user',
model: 'UserApp.model.User',
autoLoad: true,
pageSize: 10,
proxy: {
type: 'ajax',
api: {
read: 'data/readGoods.php',
update: 'data/updateGoods.php',
create: 'data/createGoods.php',
destroy: 'data/deleteGoods.php'
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
},
writer: {
type: 'json',
root: 'data',
encode: true
}
}
});


Then for each view you can specify the store by type and get a different instance of the store definition per view.



store: {
type: 'user'
// and any other config you'd like to pass to the store including distinct proxies
}

Alex_Dutch
25 May 2013, 3:29 AM
Oh, thanks.
But how to set to instatnse store a different category?
With proxy: {extraParams: { category: 'second'
or proxy: {api: {read: 'data/readGoods.php?catagory=second'

slemmon
28 May 2013, 3:59 PM
Once the store config starts to get much more diverse between implementations I'm inclined to just define two different stores. Then you can set the config for each proxy uniquely. Or I suppose if you define your store generically then you can pass a full proxy in when instantiating the store for each component, but if you do that I'm not sure it's even worth it to separate your store definition from the view config even.