これが私のDataGridです:
// $ is a reference to `this` as it lies in an anonymous function
$.grid = new DataGrid({
store : $.dataStore,
query : {id : "*"},
structure : [
{
noscroll : true,
cells : [{ name : "Recipe", field : 'name', width : '200px' }],
},
{
cells : [
[
{ name : 'ID#', field : 'id', width : '50px'},
{ name : 'Category', field : 'category', width : '100px'},
{ name : 'Status', field : 'status', width : '100px'},
{ name: "Actions", width : '200px', type: dojox.grid.cells._Widget, formatter : $._actionButtons}
]
] // end cells
}
]
}, $.targetNode)
$.grid.startup();
$.grid.on("RowClick", function(e){
console.log(this.getItem(e.rowIndex))
})
そして、formatter
Actions セルのオブジェクト:
_actionButtons : function(){
var _self = this;
var _args = arguments;
this.group = new Pane()
var full = new Button({
label: 'View Full',
style : { fontSize : '80%'},
onClick : function(){
try {
_self.grid.onRowClick.apply(this, arguments)
}catch(e){}
}
});
full._destroyOnRemove = true;
var edit = new Button({
label : 'Edit',
style : {fontSize: '80%'}
});
edit._destroyOnRemove = true;
construct.place(full.domNode, this.group.containerNode)
construct.place(edit.domNode, this.group.containerNode)
return this.group;
}
onRowClick
DataGridの通常のイベントによって渡されるイベント オブジェクトにアクセスしようとしています。今のところ、これはちょっとうまくいきますが、on("RowClick"...)
ブロックで複数のログを取得します。ブロックがないtry...catch
と、行インデックスが存在しないためエラーが発生し、存在するe
場所にさらに2つのログが表示されます。
これは、pub/sub、emit() などを含めた 4 番目程度のアイデアです。複数のログは、バブリング動作 (Button -> Row -> DataGrid など) が原因であると感じていますが、フォーマッタで作成されたボタンに渡される onRowClick のイベント オブジェクトは不可能のようです。
onClick
Button ウィジェットのイベントからrowIndex (およびその他の DataGrid 風のプロパティ) にアクセスして、押されたボタンに応じて処理したいだけです。