Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:43:54+00:00 2026-06-13T21:43:54+00:00

I have a grid that I am creating drawing off a JSON data source

  • 0

I have a grid that I am creating drawing off a JSON data source that is formatted like this:

{"recordsReturned":10,
        "totalRecords":471,
        "startIndex":0,
        "sort":"num",
        "dir":"asc",
        "pageSize":100,
        "visitors":[
            {"num":1, "uid": "1", "ipaddress": "24.217.129.98", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14", "date":1352086661000},
            {"num":2, "uid": "0", "ipaddress": "100.43.83.157", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)", "date":1351761442000},
            {"num":3, "uid": "0", "ipaddress": "100.43.83.157", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)", "date":1351718948000},
            {"num":4, "uid": "0", "ipaddress": "100.43.83.157", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)", "date":1350349829000},
            {"num":5, "uid": "0", "ipaddress": "70.36.100.148", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)", "date":1349718631000},
            {"num":6, "uid": "0", "ipaddress": "180.76.5.153", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)", "date":1349396285000},
            {"num":7, "uid": "0", "ipaddress": "76.72.166.150", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)", "date":1349090589000},
            {"num":8, "uid": "0", "ipaddress": "65.55.52.115", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)", "date":1348417348000},
            {"num":9, "uid": "0", "ipaddress": "66.249.72.195", "hostname": "", "referer": "", "useragent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "date":1348353989000},

And so on. I created this JSON format for a YUI 2 DataTable and it works well, since it contains everything I need to make sense of the record. What I did with YUI that I cannot figure out how to do with dgrid is to tell it to use the contents of the visitors array to populate the dgrid. Here is my dgrid code:

// Create a new constructor by mixing in the components
var CustomGrid = declare([ OnDemandGrid, Keyboard, Selection ]);

var grid = new declare([OnDemandGrid, Keyboard, Selection])({
    store: store,
    columns: {
        num: "ID",
        uid: "visitorsUID"
    },
    /*selectionMode: "single", // for Selection; only select a single row at a time
    cellNavigation: false // for Keyboard; allow only row-level keyboard navigation*/
}, "grid");

grid.setQuery({aid: "1604", sort: "num", dir: "asc", startIndex: "0", results: "100"});             

Is there a simple way to tell dgrid to draw from that subrow/array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:43:55+00:00Added an answer on June 13, 2026 at 9:43 pm

    I can see multiple options here, but the most straightforward would be writing your own Store satisfying the interface of dojo/store/api/Store or just hack it and subclass dojo/store/JsonStore:

    var CustomStore = declare(JsonRest, {
        query: function(query, options) {
            var dataProperty = this.dataProperty;
            var results = this.inherited(arguments);
            var deferred = results.then(function(result) {
                return result[dataProperty];
            });
            return QueryResults(deferred);
        }           
    });
    

    then you will need to add one more property when instantiating – dataProperty:

    var store = new CustomStore({
        target: "/visitors/",
        idProperty: "num",
        dataProperty: "visitors"
    });
    

    See it in action at jsFiddle: http://jsfiddle.net/phusick/MG9jB/

    Other option would be to change the response before it reaches dojo/store/JsonRest, so JsonRest gets what it expects, an array. Dojo 1.8 provides dojo/request which employs XHR2 thus it unfortunately does not work with JsonRest, but just for the sake of elegancy:

    // var request = require("dojo/request/registry");
    // var xhr = require("dojo/request/xhr");
    
    var handle = request.register(/(.*)\/visitors.json$/, function(url, options) {
        // if any XHR request url ends with `visitors.json` then return
        // `visitors` property
        return xhr.get(url, options).then(function(results) {
            return results["visitors"];
        });
    });
    
    request.get("app/visitors.json", {handleAs: "json"}).then(function(visitors) {
        console.log(visitors);
    });
    

    In the article Introducing dojo/request one can find a reference to dojox/io/xhrPlugins which should provide similar functionality against legacy code. And even if it does not, you can use dojo/aspect or possibly write your own content handler to achieve the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some grid that looks like this _ _ _ _
I have following code that I creating a grid var store = Ext.create('Ext.data.ArrayStore', {
I am creating a GridView/DetailsView page. I have a grid that displays a bunch
I have a grid something like this: A A A A A B C
I'm creating an interface programmatically that contains a grid of cells. I'd like the
I have a javascript class that I'm creating. This class has private and public
I have a problem with creating a GridView-based calendar. Here is the Grid: This
I have an ASP.NET GridView which has columns that look like this: | Foo
I have a simple ListView, essentially creating a MxN grid. FullRowSelect is off. Essentially
I have a grid that has multiple rows. I want to hide/show one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.