先看代码:             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的值呢?值为“列名称”
试了几个都取不到,请教下各位大虾。。

解决方案 »

  1.   

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

  2.   

    直接用this就好了,var columns=this.columns;难点主要在取cellIndex值吧,还有一个很容易造成误解的地方,就是会用header,没想到用text,columns[cellIndex].header这样又取不到值了。