PDA

View Full Version : can I get owner from a store?



moegal
14 Dec 2010, 6:44 AM
Hi,

I want to set a value of a combo after the store is loaded. I am using lazy and each store is unique to the combo. This is a simple example and it is doing more then simple setting the value. So how can I reference the combo for the store? Without a separate store? And I cannot set an ID for each field.



{
xtype: 'combobox',
fieldLabel: 'Customer ID',
name: 'customerID',
hiddenName: 'customerID',
valueField: 'lookupid',
displayField: 'lookupname',
onDo: 'select',
allowBlank: false,
forceSelection: true,
triggerAction: 'all',
mode: 'remote',
lazyInit: false,
store: new Ext.data.JsonStore({
url: 'includes/get-combo.asp',
autoLoad: false,
root:'Records',
totalProperty: 'RecordCount',
fields:['lookupid', 'lookupname', 'linkedid'],
id: 'lookupid',
listeners: {
'load': function(store) {
// combo.setValue(''); // I need to know what combo is??? }
}
})
}


Thanks, Marty

darthwes
14 Dec 2010, 7:26 AM
Add a listener for the load from the combo's afterrender event?


xtype: 'combo',
store: ...,
listeners: {
'afterrender': function() {
this.store.on('load', function(store) {
this.setValue(store.getAt(0).get('id'));
}, this);
}
}

moegal
14 Dec 2010, 9:41 AM
Wes,

That seems to work. I did not think I could do that.

Marty

Ballsacian1
14 Dec 2010, 11:02 AM
xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'includes/get-combo.asp',
autoLoad: false,
root:'Records',
totalProperty: 'RecordCount',
fields:['lookupid', 'lookupname', 'linkedid'],
id: 'lookupid',
listeners: {
'load': function(store) {
this.getCombo().setValue(store.getAt(0).get('id'));
},
scope: this
}
})


In what was presented in both posts above this probably refers to the class which contains the items of which include that combo. So this would refer to that parent class and not to the combo.

moegal
14 Dec 2010, 11:07 AM
what is: getCombo() ? I don't see it in the docs.

Ballsacian1
14 Dec 2010, 11:09 AM
what is: getCombo() ? I don't see it in the docs.

That would be a function which either uses the ref attribute on combo to look it up and return it, a this.getComponent(#) call, or a form.getForm().findField(FIELDNAME) call. Just a stub function which you would need to implement to return the combo to you so that you can change the value.

moegal
14 Dec 2010, 12:46 PM
thats just it. Can't easily get the id of the combobox from the store when the store is created inline. Wes's post seems to work.

Ballsacian1
14 Dec 2010, 12:51 PM
the listeners object can take a scope attribute so that when your load function is called it can be given the scope of the parent class enabling you to then reach out to the combo. It really depends on how early you need to have the load event be able to be triggered. in darthwes's example it will wait till after the form renders before it can catch load events from the combo.

moegal
14 Dec 2010, 2:08 PM
so how would I set the scope of the listener of an inline store to that of the lazy combobox? Setting the scope to "this" returns DOMWindow.

Thanks, Marty

Ballsacian1
14 Dec 2010, 2:15 PM
listeners: {
load: this.onStoreLoad,
scope: this
}

moegal
14 Dec 2010, 2:29 PM
I must be doing something wrong, I still get DOMWindow.



xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'includes/get-combo.asp',
autoLoad: false,
root:'Records',
totalProperty: 'RecordCount',
fields:['lookupid', 'lookupname', 'linkedid'],
id: 'lookupid',
listeners: {
'load': function(store) {
console.log(this);
},
scope: this
}
})


Thanks, Marty

Ballsacian1
14 Dec 2010, 2:41 PM
Yea I wasn't sure where you were putting your combo code so I never knew what scope you were able to get. If you are just placing the code inline on a page then you could do something like this:


var combo = Ext.form.ComboBox({
xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'includes/get-combo.asp',
autoLoad: false,
root:'Records',
totalProperty: 'RecordCount',
fields:['lookupid', 'lookupname', 'linkedid'],
id: 'lookupid',
listeners: {
'load': function(store) {
combo.setValue(1);
}
}
})

or


xtype: 'combo',
id:'aSingleOneTimeUseCombo',
store: new Ext.data.JsonStore({
url: 'includes/get-combo.asp',
autoLoad: false,
root:'Records',
totalProperty: 'RecordCount',
fields:['lookupid', 'lookupname', 'linkedid'],
id: 'lookupid',
listeners: {
'load': function(store) {
Ext.getCmp('aSingleOneTimeUseCombo').setValue(1);
},
scope: this
}
})

Either way the other response to this thread will also work and is really more a matter of preference as well as when your store needs to load in comparison to when the combo renders.

moegal
14 Dec 2010, 2:44 PM
thanks for trying, but i can't use either method. I need to use the lazy method so the 1st option is out and I am cloning the fields so i cannot set the id in method 2.

Again, thanks for trying.

Marty

Ballsacian1
14 Dec 2010, 2:45 PM
If you are cloning the fields why not just extend combobox into a custom class. In doing this scope works so much better and works as I've shown above.

moegal
14 Dec 2010, 4:38 PM
just working on a proof of concept at the moment.