1

Is there a way to fill a Column of an dojox/grid/EnhancedGrid with SubObjects in a JSON Structure? For example if i have a JSON-Row that is looking like:

   {
        id: 2,
        name: "TestItem2",
        created: {
             date: "2013-03-28 11:59:40",
             timezone_type: 3,
             timezone: "Europe/Berlin"
        }
   }

and I want to fill a Column of the Grid with "date" in SubObject "created". I already tried something like setting the Column's "field" property to "created.date" in the Grid's "structure" Property, but that didn't do the job.

Markus Ebner
  • 148
  • 9

2 Answers2

2

Apparently you can use a formatter in this case:

var structure = [[
    {'name': 'Date', 'field': '_field', formatter: myFormatter }
]];

which will pass the whole node from the store into a function called myFormatter from which you can pass the relevant entry, like:

function myFormatter(node, rowIdx){
    return node.created.date;
};

See also citress' answer here: Dojo grid nested json

Community
  • 1
  • 1
DanMan
  • 11,323
  • 4
  • 40
  • 61
0

This is kind of evil and lame, but maybe changing the object structure will help you get it into the grid. It sounds like you just want the date, so you could do this:

var o = {
    id: 2,
    name: "TestItem2",
    created: {
         date: "2013-03-28 11:59:40",
         timezone_type: 3,
         timezone: "Europe/Berlin"
    }
};

o.created = o.created.date;

Now the object looks like this:

created: "2013-03-28 11:59:40"
id: 2
name: "TestItem2"

Here's a sample from the console:

Here's a sample from the console

Jess
  • 23,901
  • 21
  • 124
  • 145
  • @Seijikun let me know if this helps you or not. – Jess Mar 30 '13 at 02:55
  • I thought of it, but that is unfortunately not possible, because the Rest API is not changeable. That would work for the date, but the real data model contains some more SubObjects where I need more than one property of. Changing the model clientside would need to iterate through all items, and that would be really evil. – Markus Ebner Mar 30 '13 at 13:30
  • I'll leave the answer here in case it helps someone else. – Jess Mar 30 '13 at 20:13