PDA

View Full Version : [Solved] Getting Old Data before Store loads



danaxelrod
17 Jan 2011, 6:42 PM
I'm trying to update the value of a combo box, after a store is loaded, using getAt. But, the value is retrieved before the store is loaded. Is there a way to get the value after a the load? Thanks! (In my code, displaynames.getAt(0) is assigned a value from the old data store.


var updateDisplayNames = function(sval){
Ext.getCmp('nameBox').clearValue()
displaynames.load({params:{status: sval}
})
Ext.getCmp('nameBox').setValue(displaynames.getAt(0).get('displayname'))
}

vishalnnsingh
17 Jan 2011, 9:10 PM
The code you have posted does not make your problem clear, it would be great if you can post more code highlighting your probem

danaxelrod
17 Jan 2011, 9:22 PM
Sorry, I'm trying to get the first value of a data store so I can use it as a default value for a combo box. This function loads the store with displaynames.load(...) and then sets the value of the combobox 'nameBox' with displaynames.getAt(0). But it's getting not getting the newly updated data from the load function, it's getting the old stored data. I hope this makes sense.


var displaynames = new Ext.data.Store({
reader: new Ext.data.JsonReader({
fields: ['id', 'displayname'],
root: 'rows'
}),
proxy: new Ext.data.HttpProxy({
url: 'displaynames.php'
}),
autoLoad: true
});
var updateDisplayNames = function(sval){
Ext.getCmp('nameBox').clearValue()
console.log(sval)
displaynames.load({params:{status: sval}
})
Ext.getCmp('nameBox').setValue(displaynames.getAt(0).get('displayname'))
}
var patient_form = new Ext.FormPanel({
url: 'movie-form-submit.php',
renderTo: document.body,
frame: true,
title: 'Patent Search Form',

width: 450,
items: [{
xtype: 'combo',
id: 'nameBox',
hiddenName: 'displayname',
fieldLabel: 'Name',
mode: 'remote',
selectOnFocus: true,
typeAhead: true,
editable: false,
triggerAction: 'all',
store: displaynames,
displayField:'displayname',
emptyText: '-Select-',
valueField: 'id',
width: 130,
listeners: { select: {fn: function(){
updateTxDates(this.value)
}
}
}

vishalnnsingh
17 Jan 2011, 10:36 PM
Everything uis alright with your code,i think what you need to do is just place this

Ext.getCmp('nameBox').setValue(displaynames.getAt(0).get('displayname'))
in the right place.
Place it in an event handler maybe on form render, and it will work fine.

danaxelrod
17 Jan 2011, 10:42 PM
Sorry, I'm really new to ext and javascript. But could you be more specific as to where I should put that?

vishalnnsingh
17 Jan 2011, 10:51 PM
Sure, Give me a min

vishalnnsingh
17 Jan 2011, 10:52 PM
patient_form.on('render',function(){
Ext.getCmp('nameBox').setValue(displaynames.getAt(0).get('displayname'))
}

Add this after your patient_form definition.

I hope it helps.

Condor
18 Jan 2011, 12:21 AM
No, you have to wait for the store to load before you can access the data, e.g.

displaynames.load({
params: {status: sval},
callback: function(){
Ext.getCmp('nameBox').setValue(displaynames.getAt(0).get('displayname'));
}
});

vishalnnsingh
18 Jan 2011, 12:25 AM
Thanks!!! :)

danaxelrod
18 Jan 2011, 6:58 AM
Amazing :) Thanks Condor!