简体   繁体   English

将click事件添加到extjs中的网格摘要行

[英]Add click event to the summary row of grid in extjs

Asked this question yesterday but not getting any response to posting it again in diffrent words- 昨天被问到这个问题,但没有得到任何回应,以不同的方式再次发布 -

I have two columns with summary row- 我有两列摘要行 -

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' },
];

I want to add cellclick event to these summary row so that on click I can open a new window If I use cellclick event of grid, it works for all cells except this summary row. 我想将cellclick事件添加到这些摘要行,以便在单击时我可以打开一个新窗口如果我使用gridclick事件的网格,它适用于除此摘要行之外的所有单元格。

Is there any other event which I can use so that I would be able to click on it. 还有其他任何我可以使用的事件,以便我可以点击它。

UPDATE: 更新:

I have used following listener which is not working for summary row 我使用了以下监听器,它不适用于摘要行

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

As far as I know, there's no built-in event for summary row click. 据我所知,没有用于汇总行点击的内置事件。 What you can do is add a listener to the cell element itself. 你可以做的是为单元元素本身添加一个监听器。

You can do that easily by using the delegate option of the listener. 您可以使用侦听器的delegate选项轻松完成此操作。 But this option is only available for DOM elements events, so we also have to use the element option to hook our event on the grid's body element (alternatively, you can use something like myGrid.getEl().on({ ... }) ). 但是此选项仅适用于DOM元素事件,因此我们还必须使用element选项将事件挂接到网格的body元素上(或者,您可以使用类似myGrid.getEl().on({ ... }) )。

Here's an example of listeners that you would add directly to your grid's config: 以下是您将直接添加到网格配置中的侦听器示例:

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

Unfortunately, this kind of code relies on class names and the cellIndex property that are set by Ext, and that may change in the future... Keep that in mind when you upgrade the lib! 不幸的是,这种代码依赖于由Ext设置的类名和cellIndex属性,并且将来可能会改变...在升级lib时请记住这一点!

I am not sure about the code u have used adding event for row click, but still i am adding this code to grid panel hope it helps,sry if u have tried already.. I have edited this below will do i believe.. 我不确定您使用添加事件进行行点击的代码,但我仍然将此代码添加到网格面板希望它有所帮助,如果你已经尝试过sry ...我已经编辑过以下我会相信..

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

            var fieldName = iView.getGridColumns()[iColIdx].dataIndex;
console.log(fieldName );
}
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM