PDA

View Full Version : Combo box...loading



petcy
8 Oct 2010, 5:00 AM
my combo box created like this...



{
xtype:'combo',
store:mystore,
fieldLabel: 'Visitor',
displayField:'visit',
valueField:'vi',
mode: 'remote',
forceSelection: true,
name: 'visit',
typeAhead: true,
triggerAction: 'all',
selectOnFocus:true,
emptyText:'Choose a Visitor...',
anchor:'95%'

}

this visitor names are coming from the DB depending a classID(my project...)

i called a function from classID textfield... on blur event..



{
xtype:'textfield',
fieldLabel: 'class Id',
name: 'classId',
onBlur:populatevisitor,
anchor:'50%'
}


and my function like this....



var populatevisitor= function()
{


var f=formp.getForm();
var id=f.findField('classid').getValue();
Dwrclass.visitorloade(id,callback=function(vlst){
for(var i=0;i<vlst.length;i++)
{
mystore[i]=vlst[i];

}



});


i'm getting the values into the mystore array like dis:.......:aaa,bbb,ccc,...but not loading...



help........
}

jarrednicholls
8 Oct 2010, 7:22 AM
It looks like the "mystore" variable is just an array of values? Are you creating your ComboBox after you call populatevisitor? If your ComboBox is created first, then modifying "mystore" in that way will not reflect any changes in the ComboBox. ComboBox can accept an array of values, or even an array of arrays, but that input is translated into an Ext.data.ArrayStore instance. If you need to add values to your store dynamically, you must use the Ext.data.Store API (http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Store) and add Ext.data.Record instances to the Store. In other words, once the ComboBox is created, it's using a true Ext.data.Store instance, not an array of values.

Does that make sense?

petcy
10 Oct 2010, 8:33 PM
yessss u r right..
i need to create c ombobox dynamically....
i'm getting values in mystore array...
but sir....
how can i create the combobox as per the size of the array dynamically....from a 'on Blur' function()

how can i change my code???

jarrednicholls
12 Oct 2010, 10:16 AM
Hey petcy,

If you make your array of data compatible with the ArrayStore/ArrayReader by turning it into an "array of arrays", you can simply reload the store's data by calling "loadData".

Data:


var mystore = [ ['aaa'], ['bbb'], ['ccc'] ];


Reload Data:


comboBox.store.loadData(mystore);

petcy
12 Oct 2010, 8:46 PM
thts more confusing...

i don't know the size and values of the array till runtime....

cozz.... i'm fetching values from database throught the onblur function...(above code)

then what should i do????

jarrednicholls
13 Oct 2010, 6:25 AM
petcy,

That was merely an example. If you fill the values of the array at runtime, that's fine...simply start with an empty array:



var mystore = [];

//...

{
xtype:'combo',
store:mystore,
fieldLabel: 'Visitor',
displayField:'visit',
valueField:'vi',
mode: 'remote',
forceSelection: true,
name: 'visit',
typeAhead: true,
triggerAction: 'all',
selectOnFocus:true,
emptyText:'Choose a Visitor...',
anchor:'95%'
}


Then at runtime, fill it with your values:


var populatevisitor= function()
{
var f=formp.getForm();
var id=f.findField('classid').getValue();
Dwrclass.visitorloade(id,callback=function(vlst){
// Clear the array
mystore = [];
for(var i=0;i<vlst.length;i++)
{
// Insert new data. Must be an array of arrays for Ext.data.ArrayReader
mystore.push([ vlst[i] ]);
}
// Then, load the new data into the store that's attached to the combobox
comboBox.store.loadData(mystore);
});

petcy
13 Oct 2010, 8:30 PM
thats very nice of u...

its working now...
i changed a littile bit ... clear the array before the loop starts..

// Clear the array

mystore = [];


Dwrclass.visitorloade(id,callback=function(vlst){
for(var i=0;i<vlst.length;i++)
{


// Insert new data. Must be an array of arrays for Ext.data.ArrayReader
mystore.push([ vlst[i] ]);
}
});

again thank u so much jarred..

jarrednicholls
14 Oct 2010, 12:25 PM
No problem. Sorry, I meant to put the array clear before the loop, not inside of it :-) Glad you got it working!