Dojo DataGrid 未填充自定义小部件中的数据
我试图从 Dojo 1.6 中的自定义小部件生成数据网格,但仅生成与 DataGrid 对应的 HTML,并且没有数据填充到网格中。
这是自定义小部件代码:-
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.parser");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.declare("FormGenerator", [dijit._Widget, dijit._Templated], {
widgetsInTemplate: true,
templateString: dojo.cache("widget", "templates/dummyHTML.html"),
postCreate : function(){
this.inherited(arguments);
layout =
[
{ name: 'Name', field: 'name', width: '100px' },
{ name: 'Color', field: 'color', width: '100px' }
];
dataStore = {
data :
{items :[
{ name : 'John Doe', color: 'green' },
{ name : 'Jane Doe', color: 'red' }
],
label:'name',
identifier:'color'
}
};
var grid = new dojox.grid.DataGrid
(
{
store: new dojo.data.ItemFileReadStore(window.dataStore),
autoRender : true,
structure: window.layout
},
"dummy" // this id should be there in HTML .
);
grid.startup();
},
});
这是 dummyHTML.html 模板:-
<div>
<div id="dummy"></div>
</div>
此 HTML 由上面的代码生成:-
<div id="formRequirement" widgetid="formRequirement">
<div align="left" dojoattachevent="onmouseout:_mouseOut" role="grid" hidefocus="hidefocus" tabindex="0" aria-multiselectable="true" class="dojoxGrid" id="dummy" widgetid="dummy" aria-readonly="true" style="height: 0px; -moz-user-select: none;">
<div role="presentation" dojoattachpoint="viewsHeaderNode" class="dojoxGridMasterHeader" style="display: none; height: 0px;"><div role="presentation" dojoattachpoint="headerNode" class="dojoxGridHeader" style="width: 1270px; left: 1px; top: 0pt;">
<div role="presentation" style="width: 9000em;" dojoattachpoint="headerNodeContainer">
<div role="row" dojoattachpoint="headerContentNode">
<table cellspacing="0" cellpadding="0" border="0" role="presentation" class="dojoxGridRowTable">
<tbody><tr>
<th dndtype="gridColumn_dummy" style="width: 100px;" idx="0" class="dojoxGridCell dojoDndItem " id="dummyHdr0" role="columnheader" aria-readonly="true" tabindex="-1">
<div class="dojoxGridSortNode">Name</div>
</th>
<th dndtype="gridColumn_dummy" style="width: 100px;" idx="1" class="dojoxGridCell dojoDndItem " id="dummyHdr1" role="columnheader" aria-readonly="true" tabindex="-1"><div class="dojoxGridSortNode">Color</div></th>
</tr>
</tbody>
</table>
</div>
</div>
</div></div>
<div role="presentation" dojoattachpoint="viewsNode" class="dojoxGridMasterView"><div role="presentation" class="dojoxGridView" id="dojox_grid__View_1" widgetid="dojox_grid__View_1" style="width: 1270px; height: 0px; left: 1px; top: 0px;">
<input type="checkbox" role="presentation" dojoattachpoint="hiddenFocusNode" class="dojoxGridHiddenFocus">
<input type="checkbox" role="presentation" class="dojoxGridHiddenFocus">
<div role="presentation" dojoattachpoint="scrollboxNode" class="dojoxGridScrollbox" style="height: 0px;">
<div role="presentation" hidefocus="hidefocus" dojoattachpoint="contentNode" class="dojoxGridContent" style="height: 64px; width: 1255px;"></div>
</div>
</div></div>
<div dojoattachpoint="messagesNode" style="display: none;" class="dojoxGridMasterMessages"></div>
<span tabindex="0" dojoattachpoint="lastFocusNode"></span>
</div>
</div>
您可以看到上面的代码没有填充任何数据。您还可以看到我已将布局和数据存储设置为全局变量但没有成功。即使我尝试将 DataGrid 放入模板文件(dummyHTML.html)本身并通过标记初始化 DataGrid,但它也不起作用。
如果我遗漏了什么,请告诉我。
谢谢
I am trying to generate Data Grid from custom widget in Dojo 1.6, but only HTML corresponding to DataGrid is getting generated and no data is populated into Grid.
Here is custom widget code :-
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.parser");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.declare("FormGenerator", [dijit._Widget, dijit._Templated], {
widgetsInTemplate: true,
templateString: dojo.cache("widget", "templates/dummyHTML.html"),
postCreate : function(){
this.inherited(arguments);
layout =
[
{ name: 'Name', field: 'name', width: '100px' },
{ name: 'Color', field: 'color', width: '100px' }
];
dataStore = {
data :
{items :[
{ name : 'John Doe', color: 'green' },
{ name : 'Jane Doe', color: 'red' }
],
label:'name',
identifier:'color'
}
};
var grid = new dojox.grid.DataGrid
(
{
store: new dojo.data.ItemFileReadStore(window.dataStore),
autoRender : true,
structure: window.layout
},
"dummy" // this id should be there in HTML .
);
grid.startup();
},
});
Here is the dummyHTML.html template :-
<div>
<div id="dummy"></div>
</div>
This HTML is generated by above code :-
<div id="formRequirement" widgetid="formRequirement">
<div align="left" dojoattachevent="onmouseout:_mouseOut" role="grid" hidefocus="hidefocus" tabindex="0" aria-multiselectable="true" class="dojoxGrid" id="dummy" widgetid="dummy" aria-readonly="true" style="height: 0px; -moz-user-select: none;">
<div role="presentation" dojoattachpoint="viewsHeaderNode" class="dojoxGridMasterHeader" style="display: none; height: 0px;"><div role="presentation" dojoattachpoint="headerNode" class="dojoxGridHeader" style="width: 1270px; left: 1px; top: 0pt;">
<div role="presentation" style="width: 9000em;" dojoattachpoint="headerNodeContainer">
<div role="row" dojoattachpoint="headerContentNode">
<table cellspacing="0" cellpadding="0" border="0" role="presentation" class="dojoxGridRowTable">
<tbody><tr>
<th dndtype="gridColumn_dummy" style="width: 100px;" idx="0" class="dojoxGridCell dojoDndItem " id="dummyHdr0" role="columnheader" aria-readonly="true" tabindex="-1">
<div class="dojoxGridSortNode">Name</div>
</th>
<th dndtype="gridColumn_dummy" style="width: 100px;" idx="1" class="dojoxGridCell dojoDndItem " id="dummyHdr1" role="columnheader" aria-readonly="true" tabindex="-1"><div class="dojoxGridSortNode">Color</div></th>
</tr>
</tbody>
</table>
</div>
</div>
</div></div>
<div role="presentation" dojoattachpoint="viewsNode" class="dojoxGridMasterView"><div role="presentation" class="dojoxGridView" id="dojox_grid__View_1" widgetid="dojox_grid__View_1" style="width: 1270px; height: 0px; left: 1px; top: 0px;">
<input type="checkbox" role="presentation" dojoattachpoint="hiddenFocusNode" class="dojoxGridHiddenFocus">
<input type="checkbox" role="presentation" class="dojoxGridHiddenFocus">
<div role="presentation" dojoattachpoint="scrollboxNode" class="dojoxGridScrollbox" style="height: 0px;">
<div role="presentation" hidefocus="hidefocus" dojoattachpoint="contentNode" class="dojoxGridContent" style="height: 64px; width: 1255px;"></div>
</div>
</div></div>
<div dojoattachpoint="messagesNode" style="display: none;" class="dojoxGridMasterMessages"></div>
<span tabindex="0" dojoattachpoint="lastFocusNode"></span>
</div>
</div>
You can see that above code is not populating any data. You can also see that I have made layout and dataStore as Global variables but no success. Even I have tried putting DataGrid into Template file(dummyHTML.html) itself and initializing DataGrid by Markup but it was also not working.
Please tell me if I am missing anything.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,因为 dojox.grid.Datagrid 本身就是一个 Widget,所以您应该在自定义 widget 类中将属性“widgetInTemplate”设置为 true。
其次,当网格尚未附加到 DOM 时,您不应该从网格中调用“startup”方法。 “postCreate”方法在与 DOM 断开连接时呈现小部件。这不是 dojox.grid.Datagrid 应该设置的方式。事实上,dojox.grid.Datagrid 一旦被放入 DOM 中就会计算出它的大小。通过执行以下操作:
1) 删除对
2) 使用 this 创建对对象网格的类引用
3) 当对象网格附加到对象网格时,调用启动方法DOM
它应该可以工作:-)
First, because dojox.grid.Datagrid is itself a Widget, you should set the attribute "widgetInTemplate" to true in your custom widget class.
Secondly, you should not call the method "startup" from your grid when it has not yet been attached to the DOM. The method "postCreate" renders the widget while disconnected from the DOM. This is not the way dojox.grid.Datagrid is supposed to be set. Indeed, dojox.grid.Datagrid figures out its size once it has been placed in the DOM. By doing the following:
1) Remove the call to
2) Create a class reference to your object gird using this
3) Call the method startup on your reference to your object grid when it has been attached to the DOM
It should work :-)
您需要指定高度和宽度。没有它们,您的网格将仅呈现标题。
You need specify height and width. Without them your grid will render only header.