0

昨天问了这个问题,但没有得到任何回应以不同的词再次发布 -

我有两列带有摘要行-

var cols = [
      { id: 'myCol1', header: 'Price1', dataIndex: 'PRICE1', type: 'float', width: 50, summaryType: 'sum' },
      { id: 'myCol2', header: 'Price2', dataIndex: 'PRICE2', type: 'float', width: 50, summaryType: 'sum' },
];

我想将 cellclick 事件添加到这些摘要行,以便单击时可以打开一个新窗口如果我使用网格的 cellclick 事件,它适用于除此摘要行之外的所有单元格。

有没有其他我可以使用的事件,以便我可以点击它。

更新:

我使用了以下侦听器,该侦听器不适用于摘要行

listeners: {
  cellclick: function(grid, rowIndex, cellIndex) {
    // do whatever
  },
  scope: this
}
4

2 回答 2

2

据我所知,摘要行点击没有内置事件。您可以做的是向单元元素本身添加一个侦听器。

delegate您可以使用侦听器的选项轻松地做到这一点。但是此选项仅适用于 DOM 元素事件,因此我们还必须使用该element选项将我们的事件挂钩到网格的 body 元素(或者,您可以使用类似的东西myGrid.getEl().on({ ... }))。

这是您将直接添加到网格配置中的侦听器示例:

listeners: {
    scope: this
    ,click: {
        element: 'body'
        // Would have been great to use '.x-grid-row-summary .x-grid-cell',
        // but delegate only accept a *simple selector* which, seemingly,
        // means just one class...
        ,delegate: '.x-grid-cell'
        ,fn: function(e, target) {
            // Remove the condition if you want to catch all cells. You won't
            // have all the arguments that are available in the cellclick
            // event, though.
            if (Ext.fly(target).up('tr').is('.x-grid-row-summary')) {
                // The cellIndex is assigned by the table view when it render the
                // cell element.
                alert('Click on summary cell at index ' + target.cellIndex);
            }
        }
    }
}

不幸的是,这种代码依赖于cellIndex由 Ext 设置的类名和属性,并且将来可能会改变......升级库时请记住这一点!

于 2013-11-29T11:11:33.890 回答
0

我不确定您使用添加事件来单击行的代码,但我仍然将此代码添加到网格面板希望它有所帮助,如果您已经尝试过.. 我在下面编辑了这个我相信..

   listeners: {
      cellclick: function(iView, iCellEl, iColIdx, iRecord, iRowEl, iRowIdx, iEvent) {

            var fieldName = iView.getGridColumns()[iColIdx].dataIndex;
console.log(fieldName );
}
    }
于 2013-11-29T10:17:41.530 回答