Using Nested Fields from an XMLStore in a DataGrid in Dojo

510 Views Asked by At

I have an XMLStore I'm using for the source of a DataGrid. I'm able to pull out top-level fields for use in the data grid, however I can't figure out how to pull out deeply nested fields from the XML.

Here's a sample of my XML data:

<ns1:CourseDetail>
 <ns1:subject_code>ABC</ns1:subject_code>
 <ns1:catalog_nbr>100</ns1:catalog_nbr>
 <ns1:descr>Some Class</ns1:descr>
 <ns1:MeetingCollection>
    <ns1:Meeting>
       <ns1:meeting_nbr>1</ns1:meeting_nbr>
       <ns1:InstructorCollection>
          <ns1:Instructor>
             <ns1:fullname>John Smith</ns1:fullname>
             <ns1:id/>
          </ns1:Instructor>
       </ns1:InstructorCollection>
       <ns1:bldg_id>999</ns1:bldg_id>
    </ns1:Meeting>
 </ns1:MeetingCollection>
</ns1:CourseDetail>

And here's the javascript I'm using to set up the grid:

var gridOptions = {
  store: sectionStore,
  query: {"ns1:subject_code": "*"},
  structure: [
      {name: "Class", field: "ns1:catalog_nbr", width: "150px"}
    , {name: "Desc", field: "ns1:descr", width: "250px"}
    , {name: "Instr", field: "ns1:fullname", width: "200px"}
  ]
};

var grid = new dojox.grid.DataGrid(gridOptions, "sectionsDataGrid");
grid.startup();

I can get the catalog number and description to show up just fine in the DataGrid, but I've tried a bunch of things to target the instructor name without success so far.

How can you define a field that targets a nested element?

1

There are 1 best solutions below

0
On

Looks like the only way around is to implement get-functions on the grid for data retrieval, and then sorting is an extra added pain: When declaratively creating a dojox.grid.DataGrid - how to specify nested data in the field attribute?

I had a similar issue with my JSON-store and I ended up converting to and serializing plain DTOs instead of entities with nested properties.