PDA

View Full Version : Add/insert to store problem



krashsun
21 Dec 2010, 11:08 PM
Hi,

I am using editor grid and trying to add record in data store. After I add/insert it seems not to get reflected at the store when i query the total count. The count did not get increase. Below is my code when I click add button. Am I doing something wrong. Thanks.


function doAdd(){
var defaultData = {
id: '1',
roleName: 'adm',
create: 'true',
read: 'true',
update: 'true',
delete: 'true'
};

var recId = 100;
var r = new store.recordType(defaultData, ++recId); // create new record
store.insert(0, r);

var count = grid.getStore().getTotalCount();
alert(count);
}

mankz
22 Dec 2010, 2:17 AM
getTotalCount is used when you only display a subset of the data in your database. Try using getCount() instead.


"getTotalCount() : Number
Gets the total number of records in the dataset as returned by the server. If using paging, for this to be accurate, ...
Gets the total number of records in the dataset as returned by the server.

If using paging, for this to be accurate, the data object used by the Reader must contain the dataset size. For remote data sources, the value for this property (totalProperty for JsonReader, totalRecords for XmlReader) shall be returned by a query on the server. Note: see the Important note in load.
Parameters:

* None.

Returns:

* Number
The number of Records as specified in the data object passed to the Reader by the Proxy. <p><b>Note</b>: this value is not updated when changing the contents of the Store locally.</p>
"

krashsun
22 Dec 2010, 11:14 PM
Hi,

Using getCount also result the same. I can only perform the doAdd() function once where by the record is inserted into the store and I can query it back. But on doing multiple doAdd() on the same page, I can see that the grid rows are incremented but on getting the store I can only get one extra added record. I just want to know whether this is the behaviour of the store and anything I can do to keep all the rows in store.

Thanks.