Login Register

Dojo grid and JsonRestStore problem

I'm trying to use a JsonRestStore with a dojo grid. I'm very close to build this but I need a little help.

My problem is that the grid doesn't show the data ; I see the data is fetch, but either I have a "no data" message written on the grid, either I have an error message, depending on the data format I fetch.

Here's the code ; I tried to make this as simple as possible in order to make this work :

var Service = function(query, queryOptions) {
        return dojo.xhrGet({url:"/test/", handleAs:"json" });     }
     Service.post = function(id, value) {
        return dojo.xhrGet({url:"/test/", content:{method:"create", id:id, value:value}});     }

store = new dojox.data.JsonRestStore({target:"test", service:Service});

// the grid
dojo.addOnLoad(function(){

        // set the layout structure for the grid version 1.2
        var layout4 = [
        { name: "Test", field: "post_id", width: '40px'},
        ];

        // create a new grid:
        var grid4 = new dojox.grid.DataGrid({
            query: { post_id: '*' },
            store: store,
            structure: layout4,
        }, document.createElement('div'));
       
        dojo.byId("gridContainer4").appendChild(grid4.domNode);
        grid4.startup();
});

Now, /test/ returns this data format :

[{"post_id":"1","user_id":"1","url":"new-post","ts_created":"2008-10-01 14:16:30","status":"Live","profile_key":"title","profile_value":"new post"},{"post_id":"2","user_id":"1","url":"new-post-draft","ts_created":"2008-10-01 14:17:38","status":"Draft","profile_key":"title","profile_value":"New post draft"},{"post_id":"20","user_id":"1","url":"test-3","ts_created":"2008-10-01 22:28:46","status":"Draft","profile_key":"title","profile_value":"test"}]

I tried also to return another data format that worked using IwriteFileStore that I tried, but that got me nowhere :

{"identifier":"post_id","items":[{"post_id":"1","user_id":"1","url":"new-post","ts_created":"2008-10-01 14:16:30","status":"Live","profile_key":"title","profile_value":"new post"},{"post_id":"2","user_id":"1","url":"new-post-draft","ts_created":"2008-10-01 14:17:38","status":"Draft","profile_key":"title","profile_value":"New post draft"}{"post_id":"20","user_id":"1","url":"test-3","ts_created":"2008-10-01 22:28:46","status":"Draft","profile_key":"title","profile_value":"test"}]}

What's going wrong here ?

Any help really appreciated !
Z.

try removing the extra commas

Try removing the extra comma after 'structure: layout4'. Also, try removing the extra one at the very end of the one line of layout definition for layout4 (after the width stuff).

That's just a general tip .. may or may not help. I have not used the JsonRestStore. You might want to try shortening your returned JSON to simplify things, if nothing else...

Dylan Tynan

Commas...

Hi,

Thanks for your message. I tried and removed the commas but that did nothing. The data still won't show up.

struggling with no result from JsonRestStore in DataGrid also

I've been struggling with the same issue.
I'm using 1.2.0 final with FF3 and IE7.
The column headers appear, but no data.

My code is, essentially, the same as code posted above.
I create a JsonRestStore instance prior to addOnLoad() and create a grid programmatically in addOnLoad().

I hope someone can offer some things to try. I'm running out of ideas.

I also tried backing a FilteringSelect with a JsonRestStore without success.
When I click the widget, Firebug indicates that a request is made for the data, but nothing gets filled into the control

totalCount needed

In json returned by the service, I found I needed the following:
{ totalCount:
items : [ {}, .... ]
}
Once I added the totalCount property, my data appeared in DataGrid.

In dojox.data.JsonRestore, the following comment is in _processResults
// if we don't know the length, and it is partial result, we will guess that it is twice as big, that will work for most widgets

This suggests to me that totalCount is required in the result set.