PDA

View Full Version : When it comes to inserting a record into dataStore



NTR
5 Oct 2007, 6:10 PM
When it comes to inserting a record into dataStore, how do you supply id for the Record???



var dataStore = new Ext.data.Store({
reader: new Ext.data.ArrayReader({id: 0},[
{name: 'productName', mapping: 1},
{name: 'productCount', type: 'int', mapping: 2},
{name: 'productPrice', type: 'float', mapping: 3}
])
});

Sample data array would look like:
var productData = [ [101, 'DVD Player', 1,49.99], [102, 'AAA Batteries', 20,4.56] ];
Upon page load I cam load the above data by calling
dataStore.loadData(productData );

When user clicks on 'Add to cart' link, I want to add a new record to the Grid (dataStore)


var ProductRecord = Ext.data.Record.create(
{name: 'productName', mapping: 1},
{name: 'productCount', type:'int', mapping: 2},
{name: 'productPrice', type: 'float', mapping: 3}
);
var myNewProductRecord1 = new ProductRecord({
productName: "Sony PlayStation",
productCount: 1,
productPrice: 299.99
});
dataStore.add(myNewProductRecord1);

I didn't get how to add id to the newly created record???