Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: [HELP] Confused adding to Ext.data.Store

  1. #1
    Sencha User Phunky's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    341
    Vote Rating
    0
      0  

    Default [HELP] Confused adding to Ext.data.Store

    I'm attempting to add additional data to a DataStore but im a little confused how to do so?

    From what i've seen in the documentation

    Code:
    add( Ext.data.Record[] records ) : void
    Add Records to the Store and fires the add event.
    Add Records to the Store and fires the add event.
    Parameters:
    
        * records : Ext.data.Record[]
          An Array of Ext.data.Record objects to add to the cache.
    
    Returns:
    
        * void
    I thought i should do something like this

    Code:
    store.add({"id":"101", "name":"adding myself"});
    But of course it does not work, now im guessing im getting the format wrong? Is there something to do with Ext.data.Record?!?

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,644
    Vote Rating
    60
      0  

    Default

    You add a Record. You do have a Record definition don't you?
    Longtime Sencha geek. Outspoken advocate of pure Javascript Views. Posts my own opinions.

  3. #3
    Sencha User Phunky's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    341
    Vote Rating
    0
      0  

    Default

    Not that i know of, all im using is this kinda thing on all my stores

    Code:
    store = new Ext.data.Store({
    	proxy: new Ext.data.HttpProxy({url: 'ajax/somepage.php'}),
    	reader: new Ext.data.JsonReader(
    		{root:'results', totalProperty:'total'},
    		['id', 'name']
    	),
    	autoLoad: true,
    	remoteSort: true,
    	baseParams: {
    		limit: 100
    	}
    });
    Would the record definition not be what i have set in the reader?

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,644
    Vote Rating
    60
      0  

    Default

    ['id', 'name']

    That's your record definition. If passed an Array, it creates one from that.

    Do it explicitly.

    MyRecordType = Ext.data.Record.create(['id', 'name']);
    myrec = new MyrecordType({"id":"101", "name":"adding myself"});
    Longtime Sencha geek. Outspoken advocate of pure Javascript Views. Posts my own opinions.

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,644
    Vote Rating
    60
      -1  
    Longtime Sencha geek. Outspoken advocate of pure Javascript Views. Posts my own opinions.

  6. #6
    Sencha User Phunky's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    341
    Vote Rating
    0
      0  

    Default

    Right, im still a little confused here - i dont wish to create a whole new store, i have the store i need what i need to do is add and additional row to the already defined store.

    Hence why i was looking into Ext.data.Store.add();

    I will read into it more the way you have explained but im not sure if thats the way i need to approach it.

    Cheers tho!

  7. #7
    Sencha User Phunky's Avatar
    Join Date
    Jun 2007
    Location
    West Yorkshire
    Posts
    341
    Vote Rating
    0
      0  

    Default

    No - your right it works :S seem's very long winded that i have to first create a record when its already defined in the store :S

    Code:
    MyRecordType = Ext.data.Record.create(['id', 'name']);
    myrec = new MyRecordType({"id":"101", "name":"adding myself"});
    ds.PartnersCombo.add(myrec);
    The above worked fine!

  8. #8
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,644
    Vote Rating
    60
      0  

    Default

    Of course you should use MyRecordType as the 2nd parameter to the JsonReader constructor. They really need to reference the same function.
    Longtime Sencha geek. Outspoken advocate of pure Javascript Views. Posts my own opinions.

  9. #9
    Ext User
    Join Date
    Aug 2007
    Posts
    12
    Vote Rating
    0
      0  

    Default it not smells good

    it not smells good,i think as the record of store,we just need to add record data


    store.insert(0,new Ext.data.Record({'id':'-1','name':'defaultchoose'}, '-1'));


    it is useful

  10. #10
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Redwood City
    Posts
    30,644
    Vote Rating
    60
      -2  

    Default

    Was there a point you wanted to make? I mean apart from posting non-functioning code?
    Longtime Sencha geek. Outspoken advocate of pure Javascript Views. Posts my own opinions.

Page 1 of 2 12 LastLast

Posting Permissions

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