html文件,为dgrid表格添加自定义标签.html
<div>
<div data-dojo-attach-point="grid"></div>
</div>
js文件,为dgrid表格添加自定义标签.js
define([
"dojo/_base/declare",
"dojo/store/Memory",
"dojo/store/Observable",
"dojo/dom-construct",
"dgrid/Keyboard",
"dgrid/OnDemandGrid",
"dgrid/Selection",
"dgrid/selector",
"dgrid/extensions/Pagination",
"dgrid/extensions/ColumnResizer",
"dijit/form/Button",
"dijit/_TemplatedMixin",
"dijit/_WidgetBase",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!html文件路径/为dgrid表格添加自定义标签.html"
"dojo/domReady!"
], function(declare, Memory, Observable, domConstruct,
Keyboard, OnDemandGrid, Selection, selector, Pagination, ColumnResizer,
Button, _TemplatedMixin, _WidgetBase, _WidgetsInTemplateMixin, template) {
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: template,
data: [{
_index: 1,
userName: "haha"
}, {
_index: 2,
userName: "chanhaha"
}],
constructor: function() {
this.inherited(arguments);
},
postCreate: function() {
this.inherited(arguments);
this.main();
},
main: function() {
this._setGrid(this.data);
},
_setGrid: function(data) {
var customCell = function(object, data, cell) {
domConstruct.create("a", {
innerHTML: object.name,
style: "display:inline;cursor:pointer;color:blue;text-decoration:underline;",
onclick: function(evt) {
alert("这是一个自定义标签!");
}
}, cell.appendChild(document.createElement("div")));
};
var layout = {
col1 : selector({resizable: false, width: 40}),
name : {label: "用户名", resizable: false},
selfLabel : {label: "自定义标签", renderCell: customCell, resizable: false, width: 210}
};
this._store = new Memory({
data: data
});
this._store = new Observable(this._store);
this._grid = new(declare([OnDemandGrid, Selection, Keyboard, Pagination, ColumnResizer]))({
columns: layout,
store: this._store,
allowSelectAll: true,
style: "",
selectionMode: "toggle",
pagingLinks: 2,
rowsPerPage: 10,
pagingTextBox: true,
firstLastArrows: true,
loadingMessage: "数据加载中...",
noDataMessage: "暂无数据。"
}, this.grid);
this._grid.startup();
}
});
});