Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  80] [ 2]  / answers: 1 / hits: 46548  / 11 Years ago, sat, july 20, 2013, 12:00:00

How do I send extra parameters when using a store for a combobox in ExtJS 4?



I know that I can use extraParams in the proxy-settings, but that will affect ALL elements that is using the same store.



I.e if I have a Grid that is using a store called Users that will list all users in a system. At the same time, I have a combobox, that also uses the store Users, but this time I want to list all Users that has status=2, thus I want to send the param &status=2 on the Ajax call to the back-end.



If I use something like:



store.getProxy().extraParams = {
status: 2
};


It will work, but the Grid will at the same time be updated to also use &status=2. I ONLY want the combobox to use the param.



I guess I could turn off autoupdate on the Grid, then set the extraParams on the render event on the combobox and then unset it when the combobox gets hidden, but what would be a very ugly solution.



I can also duplicate the store to a Users2 and use that one for the combobox, but that is a ugly solution as well.



What is the correct way to do this? It must be a very common thing for most people.



UPDATE 1:



I know I can use something like:



store.load({
params:{
'foo1': bar1,
'foo2': bar2
}
});


But how would I use that in ExtJS 4 MVC? There I just specify store: Users in the form-object. How would I send those extra parameters to the .load() function?



I have tried the following:



{
xtype: 'combobox',
fieldLabel: 'Server',
name: 'server',

//store: 'ServersIP',
store: new Cloud.store.ServersIP(),

/*
listeners: {
beforeload: function(store, options) {
console.log(store);
}
},
*/

valueField: 'id',
displayField: 'name_id',
emptyText: 'Select a Server...',
editable: false
},


However, it gives error Uncaught TypeError: Cannot read property 'ServersIP' of undefined



But the name is correct:



Ext.define('Cloud.store.ServersIP', {

extend: 'Ext.data.Store',
model: 'Cloud.model.Server',


Also, where exactly would I put the listener? I assume I did not get that one correct in my example either?



UPDATE 2:



I've got a little bit further to a solution now:



store: Ext.create('Cloud.store.ServersIP', {
proxy: {
extraParams: {
param1: 'value1',
param2: 'value2'
}
},
}),


The above does NOT work. It works if I only have a one-level variable in the params to Ext.Create. For some reason, it does not like it when I pass in proxy => extraParams => param1.



This one works:



store: Ext.create('Cloud.store.ServersIP', {
aaa: 'bbb'
}),


But then of course, my extraParams are not there. Anyone know how to fix this last part?


More From » extjs

 Answers
2

This is the best code I could come up with. No listener is needed :)



Create a new instance of the users-store and change the params in that one.



xtype: 'combobox',
fieldLabel: 'Users',
name: 'users',

store: (function() {
var s = Ext.create('MyApp.store.Users');
s.proxy.extraParams = {
active: '1'
}
return s;
})(),

[#76858] Friday, July 19, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stefanicarolinat

Total Points: 145
Total Questions: 91
Total Answers: 93

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
stefanicarolinat questions
Mon, Nov 15, 21, 00:00, 3 Years ago
Fri, Apr 16, 21, 00:00, 3 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
;