alpha
alpha

Reputation: 501

Dojo gridx 1.9 and JsonRest and WCF REST service

I am trying to learn Dojo's GridX with WCF RESTservice. I am getting "No Items to Display"

The WCF Interface is set to WebMessageFormat.JSON:

[OperationContract]
[WebGet (ResponseFormat=WebMessageFormat.Json)]
List<Account> GetAccountList();

In the web config, I have set the endpoint behavior to use "webHttpBinding"

Here is the script:

require([
              'dojo/store/JsonRest',
              'gridx/Grid',
              'gridx/core/model/cache/Async', 
              'dojo/domReady!'
        ], function (Store, Grid, Cache) {


            var jsonStore = new Store({
                target: "http://server/web/Service1.svc/GetAccount"  
            });

         //test - this is working, I am seeing the data
         //jsonStore.query({}, { start: 0 }).then(function (items) {
         //    alert(items[0].AccountName);
         //});


            var columns = [
               { field: 'AccountId', name: 'AccountId' },
               { field: 'AccountName', name: 'AccountName' },
               { field: 'AccountNumber', name: 'AccountNumber' }
            ];


             var grid = new Grid({
             store: jsonStore,
             cacheClass: Cache,
             autoHeight: true,           
             structure: columns             
          });

          grid.placeAt("gridNode");

          grid.startup();

     });

I checked Fiddler and the Response Headers: Content-Length: 2790 Content-Type: text/html

Anyhelp will be appreciated!

Upvotes: 0

Views: 1219

Answers (2)

blu10
blu10

Reputation: 654

For the gridx control to work with JSONRest you need to return a content range like this Content-Range: items 0-24/66 in your response.

see this page for details http://dojotoolkit.org/reference-guide/1.9/dojo/store/JsonRest.html

Upvotes: 1

zad0xlik
zad0xlik

Reputation: 183

Add these to require section:

'dojo/store/Cache',
'gridx/core/model/cache/Async',
'dojo/store/Observable',
'dojo/store/JsonRest',
'dojo/data/ObjectStore',
'dojo/store/Memory',

Add/Edit your grid function function with the following:

        var requestString = "http://server/web/Service1.svc/GetAccount";        
        var store = new Cache(new JsonRest({target:requestString, idProperty: "id"}), Memory());
        var objectStore = ObjectStore({objectStore: store}); 

        window.grid = new Grid({
            store: objectStore,
            cacheClass: Async,
            autoHeight: true,
            structure: layout,
            modules: [SingleSort]
        });

Call the grid below:

        grid.placeAt('gridContainer');
        grid.startup();

Upvotes: 0

Related Questions