Chris Schmitz
Chris Schmitz

Reputation: 20940

Setting an extjs 6 combobox's store data at runtime results in display error

I've got a prototype of a combo box where I'm trying to set the store data at runtime.

When I try to do this, the menu under the combobox doesn't render (or it renders so small you can't actually see it). It's here on sencha fiddle:

Ext.define('ComboBoxRates',{
    extend: 'Ext.data.Store',
    alias: 'store.rates',
    storeId: 'ratescombo',
    fields: ['rate', 'description', 'price' ]
});

Ext.define('ComboPanel',{
    extend: 'Ext.panel.Panel',
    title: 'Test',
    renderTo: Ext.getBody(),
    items:[
        {
            xtype: 'combobox',
            editable: false,
            displayField: 'description',
            valueField: 'price',
        }
    ]    
});


Ext.application({
    name : 'Fiddle',

    launch : function() {

        var data = [
            {
                description: "$105: Standard Registration",
                price: "105",
                rate: "rate1"
            },
            {
                description: "$125: Non-Member Rate",
                price: "125",
                rate: "rate2"
            },
            {
                description: "$44: Price for SK tester",
                price: "44",
                rate: "rate3"
            },
            {
                description: "$11: Another price :O",
                price: "11",
                rate: "rate5"
            }
        ];

        var rates = Ext.create('ComboBoxRates');

        rates.setData(data);

        // Showing data is loaded into the store
        console.group('directly from store instance');
        rates.each(function (rate){
           console.log(rate.getData());
        });
        console.groupEnd();

        var panel = Ext.create('ComboPanel');


        panel.down('combobox').setStore(rates);

        // Showing that the data is definitely in the widget's store        
        console.group('from widget store');
        panel.down('combobox').getStore().each(function (rate){
           console.log(rate.getData());
        });
        console.groupEnd();



    }
});

I know the data is loaded into the combobox's store (open the console log in the fiddle) so I'm not sure why it's not rendering correctly.

I know this seems silly in this context, but the prototype is logic extracted out of a grid's widget column where each row has different store data.

I also built a one-step-back prototype with the same structure but the same data is inlined in the store's definition and that works:

Ext.define('ComboBoxRates',{
    extend: 'Ext.data.Store',
    alias: 'store.rates',
    storeId: 'ratescombo',
    fields: ['rate', 'description', 'price' ],
    data: [
        {
            description: "$105: Standard Registration",
            price: "105",
            rate: "rate1"
        },
        {
            description: "$125: Non-Member Rate",
            price: "125",
            rate: "rate2"
        },
        {
            description: "$44: Price for SK tester",
            price: "44",
            rate: "rate3"
        },
        {
            description: "$11: Another price :O",
            price: "11",
            rate: "rate5"
        }
    ]
});

Ext.define('ComboPanel',{
    extend: 'Ext.panel.Panel',
    title: 'Test',
    renderTo: Ext.getBody(),
    items:[
        {
            xtype: 'combobox',
            editable: false,
            displayField: 'description',
            valueField: 'price',
        }
    ]    
});


Ext.application({
    name : 'Fiddle',

    launch : function() {


        var rates = Ext.create('ComboBoxRates');

        var panel = Ext.create('ComboPanel');

        panel.down('combobox').setStore(rates);
    }
});

I thought an updateLayout would resolve the issue but it doesn't.

Is there something wrong with my code? Is there some way of setting a combobox's values at runtime?

Upvotes: 2

Views: 3289

Answers (1)

CD..
CD..

Reputation: 74096

You are missing queryMode, use queryMode: 'local' in the combo.

Working example: https://fiddle.sencha.com/#fiddle/10al

Upvotes: 2

Related Questions