Ext 4.1.1: Add new record to Store

Charles picture Charles · Jul 19, 2012 · Viewed 46.3k times · Source

I would like to add records after the initialization of a store.

I tried loadData(), loadRawData(), add() but nothing seams to work.

Here is my jsfiddle: http://jsfiddle.net/charlesbourasseau/zVvLc

Any ideas ?

Answer

Evan Trimboli picture Evan Trimboli · Jul 19, 2012

You need to set queryMode: 'local' in the combo box. Minimal example:

Ext.onReady(function() {
    var store = Ext.create('Ext.data.Store', {
        alias: 'store.ModeStore',
        autoLoad: false,
        fields: [{
            name: 'mode',
            type: 'string'
        }, {
            name: 'id',
            type: 'string'
        }],
        data: [{
            mode: 'mode1',
            id: 1
        }]
    });

    var container = Ext.create('Ext.form.field.ComboBox', {
        renderTo: Ext.getBody(),
        displayField: 'mode',
        valueField: 'mode',
        store: store,
        queryMode: 'local'
    });

    store.add({
        mode: 'mode2',
        id: 2
    });
});