本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/dy_paradise/archive/2010/01/19/5212389.aspx
Ext.grid.GridPanel有一個重大缺陷,就是單元格的內容不能選中,沒法選中就沒法複製,給用戶帶來很多不便。
分析: 用IE Developer Toolbar打開ExtJs輸出的代碼研究了一下,發現每個單元格的div都有一個屬性:unselectable="on",看來是css在作怪。
版本: 2.2 (也適用v3+)
解決辦法: extJs官方論壇上有具體的解決辦法,比較可行的如下。
step1:添加新的css樣式。
<style type= "text/css" >
.x-selectable, .x-selectable * {
-moz-user-select: text! important ;
-khtml-user-select: text! important ;
}
</style>
step2:修改Ext.grid.GridPanel的protoType,我是自己寫了一個新的js文件,記得要在ext-all.js後面引入。
if (!Ext.grid.GridView.prototype.templates) {
Ext.grid.GridView.prototype.templates = {};
}
Ext.grid.GridView.prototype.templates.cell = new Ext.Template(
'<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}" style="{style}" tabIndex="0" {cellAttr}>' ,
'<div class="x-grid3-cell-inner x-grid3-col-{id}" {attr}>{value}</div>' ,
'</td>'
);
done!現在GridPanel的單元格可以選中了。