单击grid时,如何取到当前所在列的标题值
先看代码:
JScript code
Ext.create("Ext.grid.Panel",{
id: "test",
name: "test",
title: "表格",
layout: "fit",
columnLines: true,
store: store,采购流程
columns:[{
header: "列名称",
width: 95,
sortable: true,
align: "left",
dataIndex: "name"
}
],
listeners: {
itemclick: function(view, model, item, index, e, options){
alert("1"+index);//行索引
alert("2"+item.header);//取不到header值
}
}
});
如代码中所示,现我单击“列名称”所在的这个单元格,我在itemclick事件中,如何取得header的值呢?值为“列名称”
JScript code itemclick: function(view, model, item, index, e, options){
var columns=Ext.getCmp('test').columns;//原本想调用Ext.getCmp('test').getInitialConfig()获取配置的,但是发现此方法得不到原来的配置,得到{},是空的,不知道是不是Ext的bug还是我理解错getInitialConfig方法了
,cellIndex=Ext.get(e.target||e.srcElement).parent('td',true).cellIndex;//获得点击到的表格单元格td的列坐标
alert(columns[cellIndex].text) }
直接用this就好了,var columns=this.columns;难点主要在取cellIndex值吧,还有一个很容易造成误解的地方,就是会用header,没想到用text,columns[cellIndex].header这样又取不到值了。