12
var store = new Ext.data.JsonStore({
    id:'jfields',
    totalProperty:'totalcount',
    root:'rows',
    url: 'data.php',  
    fields:[{ name:'jfields' },
            { name:'firstyear' , mapping :'firstyear' , type:'float' },
            { name:'secondyear', mapping :'secondyear',    type:'float' },
            { name:'thirdyear' , mapping :'thirdyear' , type:'float' },
            { name:'fourthyear', mapping :'fourthyear',    type:'float' },
            { name:'fifthyear' , mapping :'fifthyear' ,    type:'float' } ]

    }                                                    
});

What I want is to add data at the end for this store , but I am totally confused , what I did is I add the following code to it but not working.

listeners: {
    load : function(){
        BG_store.add([{"jfields":"Monthly","firstyear":22.99,"secondyear":21.88,"thirdyear":21.88,"fourthyear":22.99,"fifthyear":21.88}]);
    }
}

But I do not think my concept are cleared ,Please any body show some way how to do it .

Chau
  • 5,540
  • 9
  • 65
  • 95
Amit Sharma
  • 1,968
  • 5
  • 24
  • 35

3 Answers3

16

You need to define a record type, create it and at it, e.g:

TaskLocation = Ext.data.Record.create([
    {name: "id", type: "string"},
    {name: "type", type: "string"},
    {name: "type_data", type: "string"},
    {name: "display_value", type: "string"}
]);

Then:

var record = new TaskLocation({
    id: Ext.id(),
    type: "city",
    type_data: "",
    display_value: "Brighton"
});

Then:

my_store.add(record);
my_store.commitChanges();

Remember by the time the data is in the store it's not in the same format as you sent it down but in Record objects instead.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
  • thanyou very much LIoyd , also i have figure out a way i am adding my answer too ,Once again Thankyou very much – Amit Sharma Aug 04 '10 at 16:59
6

See the recordType property in the JsonStore. It's a function that can be used as a record constructor for the store in question. Use it like this:

var newRecord = new myStore.recordType(recordData, recordId);
myStore.add(newRecord);
Roy Tinker
  • 10,044
  • 4
  • 41
  • 58
5

I have also figured out a simple solution to this:

listeners: {
    load: function( xstore ,  record , option ) {
        var u = new xstore.recordType({  jfields : 'monthly'  });
        xstore.insert(record.length, u);
    }
}

Here what I have to add is this listeners as when the data loads it will create the record type and u can add fields as data as many as u want

Chau
  • 5,540
  • 9
  • 65
  • 95
Amit Sharma
  • 1,968
  • 5
  • 24
  • 35