tags:

views:

921

answers:

2

I don't see anything in the read API that provides access to this: http://api.dojotoolkit.org/jsdoc/1.3.2/dojo.data.api.Read

+1  A: 

An example at dojocampus demonstrates one way. Here a fetch without query parameter returns all the items in the store.

var store = new some.Datastore();
var gotItems = function(items, request){
  console.log("Number of items located: " + items.length);
};
store.fetch({onComplete: gotItems});
Maine
A: 

The format of the wire-data of any data store is completely store-specific. In order for you to get the total items count (and other metadata), it must be returned as part of the response. This is the only way to do server-side pagination.

All the stores I have implemented expect the data to contain a totalCount attribute, like so:

{
  identifier: 'id',
  items: [
    { id: 123, name: 'aaa', ... },
    { id: 456, name: 'bbb', ... },
    ...
  ],
  totalCount: 525
}

The store saves this when the query returns (in onComplete). The value is then exposed via a getTotalCount() method on the store.

When used in conjunction with the start and count request options, this allows you to have nice ajax pagination ("Showing 1-50 of 525").

Since this is not part of the API, the core implementations of the read API do not implement it. A form of this technique (similar to what I have done) does seem to be implemented by the dojo.data.QueryReadStore, so you can probably look there also.

tommyjr