1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    12
    Vote Rating
    1
    mgolus is on a distinguished road

      0  

    Default Unanswered: Combobox Select Default When Using Remote, Paged Store?

    Unanswered: Combobox Select Default When Using Remote, Paged Store?


    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

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,781
    Answers
    356
    Vote Rating
    167
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    12
    Vote Rating
    1
    mgolus is on a distinguished road

      0  

    Default


    Thanks.

    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:

    Code:
    setValue: function (value, doSelect) {
         if (Ext.isObject(value) && !value.isModel &&
                !this.store.isLoaded && this.queryMode == 'remote') {
                this.setHiddenValue(value[this.valueField]);
                this.value = value[this.valueField];
                this.setRawValue(value[this.displayField]);
            } else {
                this.callParent(arguments);
            }
        }
    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?

Thread Participants: 1

Tags for this Thread