SitePen/dgrid — Issue #109: dgrid with async stores ?!?
Author: teslan
Created: 2012-03-02 02:08:43+00:00
State: open

Relevant code in original dojo/store/JsonRest.js looks like this:

var results = xhr("GET", {
url: this.target + (query || ""),
handleAs: "json",
headers: headers
});
results.total = results.then(function(){
var range = results.ioArgs.xhr.getResponseHeader("Content-Range");
return range && (range=range.match(/\/(.*)/)) && +range[1];
});
return QueryResults(results);

I tried all sorts of variations of this:

var results = xhr("GET", {
url: this.target + (query || ""),
handleAs: "json",
headers: headers
});

results = results.then(function(response){
var r = response.rows;
r.total = response.total_rows;
return r;
});
return QueryResults(results);

In the origial, results are returned as is and in my case it is results.rows that need to be returned. In addition,

Now, as soon as I do that, results.total either does not end up being returned as "promised" or as I suspect dgrid is not using the promised value and is instead using either the results.length or worse the default value of 25.

While I am personally new to JS and much of web dev, half a dozen folks on #dojo have tried to help. Out of numerous tests that exist and as I was told work ;) I am still not able to identify any that work with async (xhr like) store.

I need to get this to work in original JsonRest.js + above changes - to see paging work with async stores. Then I need to replace xhr with io.script , for a stripped down JSONP version. But in all those cases results.child.array needs to be returned to dgrid, as well as an indication of how many records are available to the query, so that dgrid will know to call store.query for more data (I hope).