2

这可能是我想念的非常简单的事情,但我不明白为什么我的听众不能在这里工作。

我在下面定义了一个包含几列的网格:

    ...
    {header: 'Privacy', dataIndex: 'PRIVACY_INDICATOR', flex: 3, tdCls: 'grid_cell'},
    {header: 'Lineage', dataIndex: 'popup', renderer: renderPopupIcon, flex: 1, tdCls: 'pop_cell', id: 'lineage_button',
        listeners:  {
            cellclick: function(record) {
                alert('cell has been clicked');
            }
         }
}

我已经尝试了所有方法,但似乎无法触发警报。

有任何想法吗?

4

2 回答 2

3

cellclick事件可用于网格而不是列。您已cellclick在应将其添加到网格的列上添加了侦听器。参见下面的示例,您可以在列的Ext Doc代码编辑器上运行它,只需复制并粘贴它并选择Live Preview

Ext.create('Ext.data.Store', {
    storeId:'employeeStore',
    fields:['firstname', 'lastname', 'seniority', 'dep', 'hired'],
    data:[
        {firstname:"Michael", lastname:"Scott", seniority:7, dep:"Management", hired:"01/10/2004"},
        {firstname:"Dwight", lastname:"Schrute", seniority:2, dep:"Sales", hired:"04/01/2004"},
        {firstname:"Jim", lastname:"Halpert", seniority:3, dep:"Sales", hired:"02/22/2006"},
        {firstname:"Kevin", lastname:"Malone", seniority:4, dep:"Accounting", hired:"06/10/2007"},
        {firstname:"Angela", lastname:"Martin", seniority:5, dep:"Accounting", hired:"10/21/2008"}
    ]
});

Ext.create('Ext.grid.Panel', {
    title: 'Column Demo',
    store: Ext.data.StoreManager.lookup('employeeStore'),
    columns: [
        {text: 'First Name',  dataIndex:'firstname'},
        {text: 'Last Name',  dataIndex:'lastname'},
        {text: 'Hired Month',  dataIndex:'hired', xtype:'datecolumn', format:'M'},
        {text: 'Department (Yrs)', xtype:'templatecolumn', tpl:'{dep} ({seniority})'}
    ],
    listeners: {
        cellclick: function(view, td, cellIndex, record, tr, rowIndex, e, eOpts) {
            Ext.Msg.alert('Selected Record', 'Name : ' + record.get('firstname') + ' ' + record.get('lastname'));
        }
    },
    width: 400,
    forceFit: true,
    renderTo: Ext.getBody()
});

更新 :

如果您只想为特定的单元格/列捕获事件,您可以使用作为函数参数cellIndex之一的属性。cellclick例如:您想在用户单击Lineage列并且该列是第 4 列时显示警报,您将使用以下代码:

cellclick: function(view, td, cellIndex, record, tr, rowIndex, e, eOpts) {
    // if clicked on cell 4, show popup otherwise ignore
    if(cellIndex == 3) { // cellIndex starts from 0
        Ext.Msg.alert('Selected Record', 'Name : ' + record.get('firstname') + ' ' + record.get('lastname'));
    }
}
于 2013-10-07T06:10:35.480 回答
1

您使用的是哪个版本的 ExtJS?请注意,在某些版本(肯定是 4.1.1)中,cellclick事件根本没有被触发(请参阅官方文档中的评论)。如果是这种情况,请尝试使用itemclick事件。另一个原因可能是你正在捕捉这个事件

cellclick: function(record) {..

你应该和

cellclick: function(field, td, cellIndex, record, tr, rowIndex, e, eOpts) {..
于 2013-10-04T19:11:59.147 回答