Dojo DataGrid, programmatic creation
Posted
by djna
on Stack Overflow
See other posts from Stack Overflow
or by djna
Published on 2010-04-16T13:09:32Z
Indexed on
2010/04/16
13:13 UTC
Read the original article
Hit count: 410
dojo
|JavaScript
I'm trying to create a DataGrid dynamically. Declarative creation is working fine:
A source of data:
<span dojoType="dojo.data.ItemFileReadStore"
jsId="theStore" url="dataonly001.json">
</span>
a simple layout:
<script type="text/javascript" >
var layout = [ {
field: 'custId',
name: 'Id',
} // more items elided ...
];
</script>
The grid:
<body class="tundra" id="mainbody">
<div id="grid"
dojoType="dojox.grid.DataGrid"
store="theStore"
structure="layout"
autoWidth="true"
></div>
</body>
And I get the grid displayed nicely. Instead, I want to create the grid dynamically. For the sake of figuring out what's broken I've tried to use exactly the same layout and store, removing just teh grid declaration and adding this script:
<script type="text/javascript" djConfig="parseOnLoad: true, debugAtAllCosts: true">
dojo.addOnLoad(function(){
// initialise and lay out home page
console.log("Have a store:" + theStore);
console.log("Have a structure:" + layout);
var grid = new dojox.grid.DataGrid({
id:"grid",
store : theStore,
clientSort : "true",
structure : layout
});
grid.startup();
dojo.place(grid.domNode, dojo.body(), "first");
});
</script>
The effect that I get is a completely empty rectangle is displayed. Using FireBug I can see that the DataGrid widget is created but that it has no rows or columns. So my guess is that the datastore or layout are not being passed correctly. However, it does appear that at the point of creation the values of theStore and layout are correct.
Suggestions please, or indeed a working example of a programmic grid might solve the problem.
© Stack Overflow or respective owner