EXTJS GRID 中 单击行和单元格获得行或者单元格的内容(数据) Js代码 复制代码 代码如下: grid.addListener("cellclick",cellclick); function cellclick(grid, rowIndex, columnIndex, e) { var record = grid.getStore().getAt(rowIndex); //Get the Record var fieldName = grid.getColumnModel().getDataIndex(columnIndex); //Get field name var data = record.get(fieldName); Ext.MessageBox.alert("show","当前选中的数据是"+data); } grid.addListener("cellclick",cellclick); function cellclick(grid, rowIndex, columnIndex, e) { var record = grid.getStore().getAt(rowIndex); //Get the Record var fieldName = grid.getColumnModel().getDataIndex(columnIndex); //Get field name var data = record.get(fieldName); Ext.MessageBox.alert("show","当前选中的数据是"+data); }
------------------------------------------------------------------------------ Js代码 复制代码 代码如下: grid.on("mouseover",function(e){//添加mouseover事件 var index = grid.getView().findRowIndex(e.getTarget());//根据mouse所在的target可以取到列的位置 if(index!==false){//当取到了正确的列时,(因为如果传入的target列没有取到的时候会返回false) var record = store.getAt(index);//把这列的record取出来 var str = Ext.encode(record.data);//组装一个字符串,这个需要你自己来完成,这儿我把他序列化 var rowEl = Ext.get(e.getTarget());//把target转换成Ext.Element对象 rowEl.set({ "ext:qtip":str //设置它的tip属性 },false); } }); grid.on("mouseover",function(e){//添加mouseover事件 var index = grid.getView().findRowIndex(e.getTarget());//根据mouse所在的target可以取到列的位置 if(index!==false){//当取到了正确的列时,(因为如果传入的target列没有取到的时候会返回false) var record = store.getAt(index);//把这列的record取出来 var str = Ext.encode(record.data);//组装一个字符串,这个需要你自己来完成,这儿我把他序列化 var rowEl = Ext.get(e.getTarget());//把target转换成Ext.Element对象 rowEl.set({ "ext:qtip":str //设置它的tip属性 },false); } });