ExtJs的GridView中,表格里显示出来的内容默认是无法选择和复制的,找了半天也没找到在哪儿可配。
网上有一种解决方案:
First, you will need to add the following CSS in your main stylesheet.
.x-grid-row ,.x-grid-cell, .x-unselectable, .x-unselectable * {
-webkit-user-select: text !important;
-o-user-select: text !important;
-khtml-user-select: all !important;
-ms-user-select: text !important;
user-select: text !important;
-moz-user-select: text !important;
}
Next, just place the following code somewhere in the top of your application javascript file.
if(typeof Ext != 'undefined'){
Ext.core.Element.prototype.unselectable = function(){returnthis;};
Ext.view.TableChunker.metaRowTpl = [
'<tr class="' + Ext.baseCSSPrefix + 'grid-row {addlSelector} {[this.embedRowCls()]}" {[this.embedRowAttr()]}>',
'<tpl for="columns">',
'<td class="{cls} ' + Ext.baseCSSPrefix + 'grid-cell ' + Ext.baseCSSPrefix + 'grid-cell-{columnId} {{id}-modified} {{id}-tdCls} {[this.firstOrLastCls(xindex, xcount)]}" {{id}-tdAttr}><div class="' + Ext.baseCSSPrefix + 'grid-cell-inner ' + Ext.baseCSSPrefix + 'unselectable" style="{{id}-style}; text-align: {align};">{{id}}</div></td>',
'</tpl>',
'</tr>'
];
}
应该可行,不过没试过。
换了一种比较暴力的方式去实现,修改extJs的源码,找到unselectable这个function,注释掉
me.swallowEvent(“selectstart”, true);
修改ext的css文件, 找到.x-grid-cell-inner,添加如下几行:
现在表格里面的内容就可以被复制了。
更正:
其实只要在GridPanel的配置项中,加入这个配置就可以了: