Results 1 to 5 of 5

Thread: How to insert a new record to a store

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Mar 2009
    Vote Rating

    Default Answered: How to insert a new record to a store

    Hi there,

    i defined a store

    Ext.define( '' , {
        extend: '',
        autoLoad: true, fields: ['display', 'value'], name: 'myStore', storeId: 'myStore',
        proxy: {
            type: 'ajax', url:'myUrl',
            extraParams: { ... },
            reader: {
                type: 'json', root: 'data', idProperty: 'value'
    in my Application I create this store via

    var store = Ext.create( '', {} );
    so far everything works fine, the store is loaded and used within a combobox.
    now I want to add a new record to the store and I tried
    store.add({ display: 'abc', value: '0' });

    store.insert( 0, { display: 'abc', value: '0' });

    since the data of the loaded store start their values from 1-15 I thought 0 or 16 should work but there simple happens nothing. No error, no new entry.

    What am I doing wrong?



  2. If you specify fields instead of a model then the store will create an implicit model. This shouldn't be a problem.

    When you call add() or insert() it is expecting to be passed records. However, from a quick look at the code, it is clear that if you don't pass it records it will create a record for you from the model (in your case, the implicit model).

    I tried your code for myself and as far as I could tell it works fine: add() and insert() both do exactly what you'd expect.


    If the data is loaded via Ajax then you have to wait until after the data is loaded before adding the new record. When the Ajax request completes it will blow away any existing records before adding its new records.

    I also briefly had a problem using the store with a combobox. I forgot to include queryMode: 'local', which resulted in a second Ajax request being made that blew away my new record. This is easily diagnosed, just watch the network activity in Firebug or the Chrome Developer Tools to check it isn't performing an extra request.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts