json - Create dojox datagrid structure layout programmatically/dynamically -
i want create dojo datagrid header looking :
as can see want section headers (section a, section b...), containing many "subheaders" (a1, a2, a3... b1, b2...). data in json response when call page. able 2 things :
first, data in json display subheaders, :
var gridstructure = [ {width:'150px', name:'table'} ]; for(var = 0 ; < response.columns.length ; i++) { for(var j = 0 ; j < response.columns[i].sections.length ; j++) { var subcolumntoadd = {width:'200px', name:response.columns[i].sections[j].sectionname}; gridstructure.push(subcolumntoadd); } } grid.setstructure(gridstructure);
and able display table how want, not dynamically :
var gridstructure = [{ cells:[ [{width: 'auto'}], [{ name: 'section a', colspan: 2 }], [{ name: 'a1', field: 'col1' }, { name: 'a2', field: 'col2' }] ], onbeforerow : function(indataindex, insubrows) { insubrows[0].invisible = true; } }]; grid.setstructure(gridstructure);
now don't know how mix it, fill headers/subheaders dynamic data. , advices.
try this:
var gridstructure = [ [ {width:'150px', name:'table', rowspan: 2} ] ]; for(var = 0 ; < response.columns.length ; i++) { for(var j = 0 ; j < response.columns[i].sections.length ; j++) { var subcolumntoadd = {width:'200px', name:response.columns[i].sections[j].sectionname}; gridstructure.push(subcolumntoadd); } }
but adding table statically... make dynamic, you'll still need (perhaps in data itself) specifies value colspan/rowspan display properly.
to add data, need build json array of data. each item of array object containing single item. should straightforward if data in format, otherwise create loop , build item dynamically.
var items = [ { name: "first", someproperty: true}, { name: "second", someproperty: false} ];
once have it, there many options on how build stores:
store = new memory({ data: items }); datastore = new objectstore({ objectstore: store }); mygrid.set("store", datastore);
or
grid = new datagrid({ store: datastore, ...
you can use reference/example https://dojotoolkit.org/documentation/tutorials/1.9/datagrid/demo/datagrid-subrows.php
Comments
Post a Comment