How to get the number of items (size) of a dojo data store?

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

+5
source share
5 answers

The wired data format of any data warehouse depends entirely on the store. To get the total number of items (and other metadata), it must be returned as part of the response. This is the only way to do pagination on the server side.

All the stores that I implemented expect the data to contain an attribute totalCount, for example:

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

( onComplete). getTotalCount() .

start count ajax pagination ( " 1-50 525" ).

API, API . ( , ), , dojo.data.QueryReadStore, , , .

+1

dojocampus . fetch query .

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

dojo.data.api. Read onBegin :

function size(size, request){
  // Do whatever with the size var.
}

store.fetch({query: {}, onBegin: size, start: 0, count: 0});

: http://dojotoolkit.org/reference-guide/1.7/quickstart/data/usingdatastores/faq.html#question-6-how-do-i-get-a-count-of-all-items-in-a-datastore

+2

I searched for the answer to this using the JsonRest store, and it looks like this:

On your server, you should look in the range header in the request to find out what elements need to be returned. the server should respond with a Content-Range header to indicate how many items are returned and how many total items there are:

Content-Range: items 0-24/66

From: http://dojotoolkit.org/reference-guide/dojo/store/JsonRest.html

0
source

The following code worked for me

  // questionStoreReader is a pointer that points to and can read ask.json file

  var questionStoreReader=new dojo.data.ItemFileReadStore({url:"ask.json"});

  questionStoreReader.fetch(
   {
     onComplete:function(items,request) // items is an array
      {
        alert(items.length);// number of items in ask.json
      },
   })
0
source

All Articles