ExtJs4使GridView里面的数据可以选择复制

ExtJs的GridView中,表格里显示出来的内容默认是无法选择和复制的,找了半天也没找到在哪儿可配。

网上有一种解决方案:

 

 

First, you will need to add the following CSS in your main stylesheet.

1.x-grid-row ,.x-grid-cell, .x-unselectable, .x-unselectable * {
2  -webkit-user-select: text !important;
3  -o-user-select: text !important;
4  -khtml-user-select: all !important;
5  -ms-user-select: text !important;
6  user-select: text !important;
7  -moz-user-select: text !important;
8}

Next, just place the following code somewhere in the top of your application javascript file.

01 if(typeof Ext != 'undefined'){
02   Ext.core.Element.prototype.unselectable = function(){returnthis;};
03   Ext.view.TableChunker.metaRowTpl = [
04    '<tr class="' + Ext.baseCSSPrefix + 'grid-row {addlSelector} {[this.embedRowCls()]}" {[this.embedRowAttr()]}>',
05     '<tpl for="columns">',
06      '<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>',
07     '</tpl>',
08    '</tr>'
09   ];
10  }

 

应该可行,不过没试过。

换了一种比较暴力的方式去实现,修改extJs的源码,找到unselectable这个function,注释掉

 

me.swallowEvent("selectstart", true);

修改ext的css文件, 找到.x-grid-cell-inner,添加如下几行:

 

user-select: text;
-webkit-user-select: text;
-o-user-select: text;
-ie-user-select: text;
-moz-user-select: text;
-ie-user-select: text;

现在表格里面的内容就可以被复制了。

 

更正:

 

其实只要在GridPanel的配置项中,加入这个配置就可以了:

viewConfig:{
   enableTextSelection:true
}

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值