-
8 Sep 2007 2:48 PM #1
Populate ComboBox with Inital Value f/ DB on XHR
Populate ComboBox with Inital Value f/ DB on XHR
I'm having a 'heck' of a time getting this working. How have any of you been able to populate a combobox with the initial value from a database. The DB part I know, the server side script I know as well... just can't seem to figure out how to do it on the client side (javascript).
-
8 Sep 2007 4:04 PM #2
Just use one of the combo examples (not with SimpleStore) and if you need to load the store before you click combo's trigger then call combo.store.load().
This is one combo from my app - take from it what you need:
PHP Code:// create table selection combo
var ctable = new Ext.form.ComboBox({
forceSelection: true
, editable: false
, triggerAction: 'all'
, displayField: 'objName'
, valueField: 'objName'
, store: new Ext.data.Store({
baseParams: {objName:'objList', cmd: 'getData', where:"objType='query'"}
, proxy: new Ext.data.HttpProxy({url:'/request.php', method:'post'})
, reader: new Ext.data.JsonReader({
root: 'rows'
, id: 'objName'
}, [{name:'objName'}])
})
, listeners: {
select:{fn: function(combo, record, index) {
store.baseParams.objName = combo.getValue();
store.load({params:{meta:true, start:0, limit:page}});
store.on({
load:{single:true, scope:this, fn:function() {
grid.getView().autoSizeColumns();
// grid.setEditable(false);
// debugger;
// testFn(store);
}}
});
}}
}
});
ctable.render('table-combo-ct');
Jozef Sakalos, aka Saki
A lot of valuable info at:
Saki's Extensions and Plugins
Saki's Extensions and Plugins Docs
Saki's Examples, Latest: Grid in Card Layout
Saki's Blog, Featured: Writing a Big Application in Ext, Latest: Grid MultiSearch Plugin Video
-
9 Sep 2007 1:42 PM #3
Thanks Saki, will this load the drop down options or the inital value?
-
9 Sep 2007 1:50 PM #4
Initial options. After store is loaded you can: combo.setValue(initValue);
Jozef Sakalos, aka Saki
A lot of valuable info at:
Saki's Extensions and Plugins
Saki's Extensions and Plugins Docs
Saki's Examples, Latest: Grid in Card Layout
Saki's Blog, Featured: Writing a Big Application in Ext, Latest: Grid MultiSearch Plugin Video
-
9 Sep 2007 8:07 PM #5
I also searched for a nice solution to set the initial value to what i recieve from database,
thats how i do it by now:
Code:form.load({ url: 'getdata.php?r=int', waitMsg:'Loading...', success: function(form, action) { form.findField('titel').setValue(action.result.data.titel_id); } });
-
10 Sep 2007 3:45 PM #6
Thanks Saki. Spirit is on to exactly what I am looking for. Spirit, what's behind the URL? XML? JSON?
I don't use any of the extjs forms. I only use the combobox. Is it still possible to load the initial value in this manner?
-
10 Sep 2007 8:42 PM #7
hmm... nothing special about my code, dont think that it is exactly what your are looking for, but here is the code which belongs to the first code i posted.
and my form:Code:var storeTitel = new Ext.data.Store({ proxy: new Ext.data.HttpProxy({url: 'getdata.php?r=titel'}), reader: new Ext.data.JsonReader({ totalProperty: 'results', root:'items' }, [{name: 'titel_id', mapping:'id'}, {name: 'titel_name' , mapping:'name'}]) }); storeTitel.load(); titel = new Ext.form.ComboBox({ width:170, fieldLabel: titel, name: 'titel', store: storeTitel, displayField:'titel_name', valueField: 'titel_id' , typeAhead: true, mode: 'local', triggerAction: 'all', selectOnFocus:true });
I have shortend my code to all i need for the combobox.Code:form = new Ext.form.Form({ labelWidth: 75, reader: new Ext.data.JsonReader({ successProperty: 'success', root: 'items' }, Ext.data.Record.create([ { name: 'titel_name', mapping: 'titel', type: 'string' }, { name: 'titel_id', mapping: 'id', type: 'int' } ])) });
Well, if you dont use a form, it will be necessary to set the initial value after recieving your data record. (what i do with form.load). First i thought that form load would set the initial value of the combobox automatic, cause it sets all other form fields (textfields, ...) automatic and all necessary data would be there (?!), but that didnt worked for me, so i set the initial value of comboboxes manual after form.load -> success
May be i didnt get it right, so post some code.
-
20 Mar 2012 7:51 PM #8
Pls tell me server side code to provide data to combo
Pls tell me server side code to provide data to combo
Pls tell me server side code to provide data to combo


Reply With Quote