`
atian25
  • 浏览: 462542 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

ExtJS Grid 选择文字以便复制

阅读更多

原文:http://extjs.com/learn/Ext_FAQ_Grid#How_to_select_text_in_the_grid_.28with_the_mouse.29_so_that_it_can_be_copied_to_the_clipboard

 

How to select text in the grid (with the mouse) so that it can be copied to the clipboard

 

1.相关帖子:http://extjs.com/forum/showthread.php?p=154426#post154426

 

2.下面是Condor 使用的方法:

  • 首先添加CSS:
<style type="text/css">
	.x-selectable, .x-selectable * {
		-moz-user-select: text!important;
		-khtml-user-select: text!important;
	}
</style>
  • 然后在grid的配置中使用该css

 

var grid = new Ext.grid.GridPanel({
   viewConfig: {
      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>'
         )
      }
   },
   ...
});

 

3.如果你想把它设置为GRID的默认属性,可以使用以下代码:

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>'
);

 译者注:紧跟ext-all.js的后面

 

4.如果你也想让表头文字可选,则可以相应的修改hcell模板;

5.如果你使用的是分组Grid,则需要把以上的模板定义放入到GroupingView的配置中去,而不是上文的viewConfig

 

 

译注:

 

1.看下源码:

//GridView 288行
if(!ts.cell){
  ts.cell = new Ext.Template(
    '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
      '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on"
 {attr}>{value}</div>',
    '</td>'
  );
}

 可知,以上的修改就是把unselectable去掉,并且在td的class里面多加了我们的x-selectable

 

 

2.进一步的,如果需要只针对某些列可选:

    2.1在该列的renderer(value,meta)里面,添加一句meta.selectable=true

    2.2再编辑下cell的模板,在里面判断{selectable?'someCssClass':''}

 

 

分享到:
评论
4 楼 NormRen 2012-07-01  
不错!!!!
3 楼 lunvsxiao 2010-06-17  
刚学extjs没多久呀,
紧跟ext-all.js的后面
是写在 ext-all.js文件的最后面
还是写一个js 引用在ext-all.js的后面?
2 楼 atian25 2010-06-17  
lunvsxiao 写道
CSS和JS添加在哪呀,没看懂呀?


css在该放的地方...
js就在grid的配置参数里面
1 楼 lunvsxiao 2010-06-17  
CSS和JS添加在哪呀,没看懂呀?

相关推荐

Global site tag (gtag.js) - Google Analytics