Reputation: 3302
how can I pass parameters from the view to the store in extjs?
this is my store:
Ext.define('mycomponents.store.mystore', {
extend: 'Ext.data.Store',
alias: 'store.levels',
model: 'mycomponents.model.mymodel',
storeId: 'levels',
restful: true,
autoLoad: true,
proxy: {
type: 'ajax',
headers: {
'Accept': '*/*',
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
'Authorization': localStorage.token
},
extraParams: {
sort: 'levelid',
'filter[active]': true,
'filter[idparent]': 0
},
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true,
encode: true,
root: 'data'
},
listeners: {
exception: function (proxy, response, operation) {
var error = Ext.decode(response.responseText);
Ext.MessageBox.show(
{
title: 'REMOTE EXCEPTION',
msg: error.message,
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
}
);
}
},
actionMethods: {
read: 'GET'
},
api: {
read: 'http://url...',
create: 'http://url...',
update: 'http://url...',
destroy: 'http://url...'
},
autoSave: true
},
constructor: function (config) {
this.callParent([config]);
}
});
My view:
var store = Ext.create('mycomponents.store.mystore', {});
Ext.define('mycomponents.view.myview', {
extend: 'Ext.container.Container',
id: 'leves',
alias: 'widget.levels',
xtype: 'levels',
items: [
{
xtype: 'combobox',
...
}
]
...
}
I need from the view send 'filter[idparent]': 1
, 'filter[idparent]': 2
, or whatever on combobox change. How can I achieve this?
Upvotes: 1
Views: 1349
Reputation: 3076
You need to attach on change
listener in combobox and use method setExtraParam
in store.
Example:
Ext.define('mycomponents.view.myview', {
extend: 'Ext.container.Container',
id: 'leves',
alias: 'widget.levels',
xtype: 'levels',
items: [
{
xtype: 'combobox',
listeners:{
change: function (cmp, newV, oldV, opt) {
Ext.getStore('levels').getProxy().setExtraParam('filter[idparent]', newV);
Ext.getStore('levels').load();
}
}
...
}
]
...
}
Upvotes: 2