Populate a ComboBox from a DataStore (JSON)
I would suggest downloading the code used for this example here so you have something to work with. Working examples can be found here.
Getting Started
The ComboBox is always a very usefull form field type, and populating it dynamically makes it even more usefull. We will just be creating a basic ComboBox thats populated from a JSON data source which pulls data from our database.
Setup The Reader
As with any data source, we will need to setup the reader so our data store knows how to read the JSON data were retreiving. We can pass an empty config object to JsonReader since were just populating a simple ComboBox and the second argument is a very simple record definition.
Setup The Data Store
The data source uses a standard store, which by default reads JSON formatted data.
The ComboBox
Now we just specify the store in our ComboBox instantiation code and set the displayField and hiddenName (which should be different from the name, if specified).
Setting the minChars to zero and the mode to 'remote' will make sure that the data is fetched each time the combo is clicked or focused.




Thanks for posting this. It was really helpful for me after a lot of searching.
I will add one comment that may help some people. To get my code working, for reasons I have not looked into, I had to change my reader code from:
var rd_random_employee_data = new Ext.data.JsonReader({}, [ 'id', 'name']);
to (something like):
var rd_random_employee_data = new Ext.data.JsonReader({},
[
{name: 'id', type: 'string', 'id'},
{name: 'name', type: 'string', mapping: 'name'}
]);
I’m not sure why there is any difference but it didn’t populate the combo box the first way
update: Actually, it does exactly the way you described. Please ignore my previous comment (apart from the thanks!)