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