View Full Version : Combobox Select Default When Using Remote, Paged Store?

17 May 2013, 2:10 PM
I am attempting to use a combobox in a form. The store that the combobox is bound to could potentially hold thousands of records. Therefore, I want to use the paging and remote features of the combobox. I have this working and it works beautifully.

The problem comes when I need to set a default value on the combobox (when the user needs to edit a model instead of add). I have the pageSize set to 50. Using setValue() works fine IF the record I am selecting is on the first page of the store. But, I am running into issues if the model is on other pages. setValue() won't work because it only searches what is currently loaded in the store (and any records past 50 are not loaded).

I have been searching for a way to perform this action all afternoon and finally decided it was time to post after making little to no progress...

Here is a jsfiddle of the problem in action: http://jsfiddle.net/mgolus/Z3Jpy/
You can change the id of the vendor by uncommenting/commenting out the two lines at the top

20 May 2013, 12:00 PM
You can set the value of a combo directly using setRawValue(). That will set the value of the field, but will not consider the combo's store or any records within it so if you set a value to something unique that's not represented in the store and you need a value associated with a record in the store (using the combo's valueField config) you will be in trouble.

20 May 2013, 3:32 PM

I am passing both the ID and the display value to the combobox in an object when I set the value. Because of this, I don't need to look the object up in the store when I set the value originally. I extended the ComboBox class and overrode the setValue function as follows:

setValue: function (value, doSelect) {
if (Ext.isObject(value) && !value.isModel &&
!this.store.isLoaded && this.queryMode == 'remote') {
this.value = value[this.valueField];
} else {

I know this doesn't handle every possible case, but it gets me 90% there. It allows me to set the value of the combobox without loading anything from the store. When the user clicks the trigger on the combobox, the store is then queried. It seems to work perfectly. Are there any issues with setting the value this way?