Ticket #6251 (new enhancement)

Opened 8 months ago

Last modified 3 months ago

DOJO Grid not supporting display of nested objects in JSON data

Reported by: guest Owned by: BryanForbes
Priority: high Milestone: 1.3
Component: DojoX Grid Version: 1.0
Severity: major Keywords:
Cc:

Description

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

Changed 8 months 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.

Changed 8 months ago by bill

  • milestone set to 1.3

Changed 8 months ago by guest

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

Changed 7 months 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.

Changed 3 months ago by BryanForbes

  • owner changed from sorvell to BryanForbes
Note: See TracTickets for help on using tickets.