Programmatically creating a Dojo DataGrid: "Sorry, an error occurred." Layout issue?
I'm attempting to create a DataGrid with some data retrieved from a Web Service. After a lot of suffering I realized the problem is not in the data nor in the service. I was able to create the DataGrid declaratively, but I need to do it programmatically, since I will be doing it in more complex scenarios.
I went from a complex use case to a very simple one and it's still failing. What I'm seeing is just the DataGrid, but with the classic "Sorry, an error occurred" error.
+----------+----------------------------+
| id | name |
+----------+----------------------------+
| Sorry, an error occurred |
| |
This is my simplified example:
<html>
<head>
<link rel="stylesheet" href="MyCSS.css">
<script type="text/javascript" src="lib/dojo/dojo.js" charset="utf-8"></script>
<script>
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojox.grid.DataGrid");
</script>
</head>
<body class="soria">
<div id="node" style="width:650px;height:300px"></div>
<script>
var structure = [
{field: "id", width: 20},
{field: "name", width: 100}
];
var data = [
{"id": 1, "name": "John"},
{"id": 2, "name": "Lucy"}
];
var node = dojo.byId("node");
var store = new dojo.da开发者_如何学编程ta.ItemFileReadStore({
data: data
});
var grid = new dojox.grid.DataGrid({
store: store,
structure: structure
},
document.createElement('div'));
node.appendChild(grid.domNode);
grid.startup();
</script>
</body>
</html>
I'm hoping I'm missing something really dumb. The console doesn't show errors.
Any suggestions?
The problem is that the data store requires a different format:
var store = new dojo.data.ItemFileReadStore({
data: {items: data}
});
That solves the problem.
精彩评论