Opened 13 years ago

Closed 12 years ago

Last modified 7 years ago

#6251 closed enhancement (invalid)

DOJO Grid not supporting display of nested objects in JSON data — at Version 6

Reported by: guest Owned by: Bryan Forbes
Priority: high Milestone: 1.3
Component: DojoX Grid Version: 1.0
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by Nathan Toone)

The JSON data returned by server (using JSON lib) gives me data which has nested objects.

for e.g.

serverData =    [{"ab":1,"bc":1234567891,"cd":79.23,"de":1100,"ef":2109,"fg":1000,"gh":190,"hi":900, "empDetail":{"firstName":"abc", "lastName":"def"}},{"ab":2,"bc":"1234567892","cd":80.30,"de":1200,"ef":3118,"fg":2000,"gh":290,"hi":1000, "empDetail":{"firstName":"BLAH", "lastName":"BLAHBLAH"}}];

Here, i want to access "empDetail" properties like "empDetail.firstName", "empDetail.lastName".

I am trying to define the grid layout like this:

var empView = {
	cells: [[
	            { name: 'First Name', field: 'empDetail.firstName', width: '10em' },
	            { name: 'Last Name', field: 'empDetail.lastName', width: '10em' }
	       ]]
	     }; 	

I would like to have the grid support nested objects, so i don't have to reformat the JSON data for each nested object and create a individual store for each nested object.

Change History (6)

comment:1 Changed 13 years ago by guest

All,

As a temporary solution, i am using the layout's "get" method, that passes the current row's index.

Here's how i am doing it:

var empView = {
        cells: [[
                { name: 'First Name', get:getefname, width: '10em' },
                { name: 'Last Name', get:getelname, width: '10em' }
               ]]
};

and in the "getefname" and "getelname" functions are defined as :

function getefname(inRowIndex){   
        if (gridWidget.model.getRow(inRowIndex)){                     
                return gridWidget.model.getRow(inRowIndex).emp.firstName;
        }              
}

function getelname(inRowIndex){   
        if (gridWidget.model.getRow(inRowIndex)){                            
                return gridWidget.model.getRow(inRowIndex).emp.lastName;
        }              
}

This works fine for 2-3 fields, but if have 10 different nested objects, it becomes a pain to write functions for all the fields in all these objects.

Hoping to get a better solution.

comment:2 Changed 13 years ago by bill

Milestone: 1.3

comment:3 Changed 13 years ago by guest

hi bill...any pointers on how to achieve this functionality? it would really help our current project...

comment:4 Changed 13 years ago by guest

for now i did another workaround. I used a library called SOJO (we use Java) to flatten an entire object graph into a map of key, value pairs. Each key would be the field name in the grid's view definition.

But it would be great if the grid can display the nested objects using the "dot" notation.

comment:5 Changed 12 years ago by Bryan Forbes

Owner: changed from sorvell to Bryan Forbes

comment:6 Changed 12 years ago by Nathan Toone

Description: modified (diff)
Resolution: invalid
Status: newclosed

The grid basically just calls store.getValue() and passes the attribute to the store for handling. Your store would be the one that should support the dot notation.

Closing for now - please open another bug against the store you wish to have support dot-notation.

Note: See TracTickets for help on using tickets.