Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ext 4.1.1: Add new record to Store

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 ?

like image 569
Charles Avatar asked Jul 19 '12 12:07

Charles


2 Answers

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
    });
}); 
like image 54
Evan Trimboli Avatar answered Oct 23 '22 07:10

Evan Trimboli


For a panel you can add or remove items by remove() and add()

var store = Ext.create('MyApp.store.Roles', {autoLoad: false});
store.load(function(records, action, success) {
    if (success) {
        store.remove(store.findRecord('id', 50, 0, false, true, true));//exact match
        store.add({'id':110,'name':'Agent' });
    }
});
like image 22
Udith Chandrarathna Avatar answered Oct 23 '22 05:10

Udith Chandrarathna