格式化的不是点击/选择行。它仅在设置单元格的内容(值)时执行。相反,您希望将焦点移到 onRowClicked - 网格组件上的事件。它是这样工作的:
grid.onRowClick = onRowClickHandler;
我不知道以下哪个示例会让您最接近您的目标,但 onRowClickHandler 可以这样设置:
function onRowClickHandler(evt) {
var rows = this.selection.getSelected();
// perform cell rendering here
dojo.forEach(rows, function(row) {
// this row is an item though.. you will have row._O as its index
});
}
或者
function onRowClickHandler(e) {
var cellClicked = this.focus.cell
cellClicked.formatter();
}
但是,您可能会发现在网格组件中的任何位置都没有太多对可查看数据的引用。您可以使用以下查询选择器来查找单元格数据并通过调用每个值的格式化程序来更新查看的 html。不过,您需要为自定义值设置的“拆卸”捕获先前的选择。
var prevSelectedRows = [];
function onRowClickHandler(evt) {
var idx = this.selection.selectedIndex,
rawRow = dojo.query(".dojoxGridRow:nth-child("+(idx+1)+")", this.domNode)[0],
self = this;
// perform resetting of viewable values
dojo.forEach(prevSelectedRows, function(raw) {
dojo.query('.dojoxGridCell', raw).forEach(function(cellDOM, i) {
cellDOM.innerHTML = cellDOM.innerHTML.replace("SELECTED", "");
});
});
prevSelectedRows = []; // reset prev selection
// look into grid.view.content for methods on this
// perform setting of viewable values (SELECTED)
dojo.query('.dojoxGridCell', rawRow).forEach(function(cellDOM, i) {
// this function might be of interest, lets see how it looks in console
console.log(self.layout.cells[i].formatter);
cellDOM.innerHTML = cellDOM.innerHTML + "SELECTED"
});
prevSelectedRows.push(rawRow);
}