开发者

Complex Object in Dojo Grid

开发者 https://www.devze.com 2023-01-28 23:56 出处:网络
I want to know if its possible to populate the following object into a dojo grid First off, the main object is a array of objects with 3 fields, 2 ints and ANOTHER ARRAY of objects with 5 fields. My

I want to know if its possible to populate the following object into a dojo grid

First off, the main object is a array of objects with 3 fields, 2 ints and ANOTHER ARRAY of objects with 5 fields. My question is, can I set-up a layout for the dojo grid to populate a grid with "subrows"

Here is a sample J开发者_如何学CSON

[{"ClaimID":1,"ClaimNumber":"4304021","LossDetails":[{"LossCause":"COLLISION                     ","LossDate":"\/Date(1136786400000-0600)\/",
    "LossExpense":95.00,"LossPaid":6415.21,"LossReserve":0.00},{"LossCause":"BODILY INJURY                 ","LossDate":"\/Date(1136786400000-0600)\/",
    "LossExpense":0.00,"LossPaid":250.00,"LossReserve":0.00},{"LossCause":"MEDICAL PAYMENTS              ","LossDate":"\/Date(1136786400000-0600)\/",
    "LossExpense":0.00,"LossPaid":0.00,"LossReserve":0.00},{"LossCause":"PROPERTY DAMAGE               ","LossDate":"\/Date(1136786400000-0600)\/",
    "LossExpense":0.00,"LossPaid":1893.99,"LossReserve":0.00}]}]


You can use dojox.grid.TreeGrid, the layout looks like:

new dojox.grid.TreeGrid({
    structure: [ 
        { cells: [
            [ 
                { field: "ClaimID", name: "ID" }, 
                { field: "ClaimNumber", name: "Number"},
                { field: "LossDetails", 
                    children: [
                        { field: "LossExpense", name: "LossExpense"}, 
                        { field: "LossCause", name: "LossCause" }, 
                        { field: "LossPaid", name: "LossPaid" }, 
                        { field: "LossReserve", name: "LossReserve" }, 
                        { field: "LossDate", name: "LossDate" } 
                    ]
                 }
             ]] 
         }                  
    ],
    store: jsonStore,
    queryOptions: {deep: true}
 }, dojo.byId("grid"));


Or if you just want a single cell containing some child objects data, you can attach a formatter to a cell:

{ name: "Child data", field: "field_object", formatter: present_child_info}
...
function present_child_info(value) {
var s = "";
for(var i = 0; i < value.length; i++) {
s += value[i].attribute;
}
return s;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消