1

これが私の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))
})

そして、formatterActions セルのオブジェクト:

_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;
}

onRowClickDataGridの通常のイベントによって渡されるイベント オブジェクトにアクセスしようとしています。今のところ、これはちょっとうまくいきますが、on("RowClick"...)ブロックで複数のログを取得します。ブロックがないtry...catchと、行インデックスが存在しないためエラーが発生し、存在するe場所にさらに2つのログが表示されます。

これは、pub/sub、emit() などを含めた 4 番目程度のアイデアです。複数のログは、バブリング動作 (Button -> Row -> DataGrid など) が原因であると感じていますが、フォーマッタで作成されたボタンに渡される onRowClick のイベント オブジェクトは不可能のようです。

onClickButton ウィジェットのイベントからrowIndex (およびその他の DataGrid 風のプロパティ) にアクセスして、押されたボタンに応じて処理したいだけです。

4

1 に答える 1

0

同じ方向に沿っていますが、これは私が思いついたもので、私が思い描いていることが起こる方向に働いているようです. ボタンが配置される調整されたセル:

{ name: "Actions", width : '200px', type: dojox.grid.cells._Widget, formatter : 
    function(){
        return $._actionButtons.call($, arguments);
    }
}

onClick返されたボタン ウィジェットの調整された関数:

_actionButtons : function(){
    var _index = arguments[0][1],
        _item  = this.grid.getItem(_index)
        _self  = this;

    // some code removed

    onClick : function(){
        console.log(_self.dataStore.getValue(_item, 'name'), "clicked")
    }
}

これをもう少しうまく処理するために Button を拡張することになるでしょうが、今のところ、出来上がりです!

時には、それを書き留めてそこに置くことで、脳がパニックに陥り、他の人よりも先に解決策を見つけ出すことができます :)

マイナーアップデート...

DataGridのパラメーターがありformatterScopeますが、すべての に適用されるため、formatterDataGrid スコープではなくセル スコープを必要とするものはすべて台無しになります。上記の方法により、必要なものすべてにアクセスできます。

于 2012-06-21T08:24:18.133 に答える