ExtJS 4(Sencha)中的网格默认情况下不允许选择内容。但我想让这成为可能。
我试过这个网格配置:
viewConfig: {
disableSelection: true,
stripeRows: false,
getRowClass: function(record, rowIndex, rowParams, store){
return "x-selectable";
}
},
使用这些css类(基本上针对我在Chrome中可以看到的每个元素):
/* allow grid text selection in Firefox and WebKit based browsers */
.x-selectable,
.x-selectable * {
-moz-user-select: text !important;
-khtml-user-select: text !important;
-webkit-user-select: text !important;
}
.x-grid-row td,
.x-grid-summary-row td,
.x-grid-cell-text,
.x-grid-hd-text,
.x-grid-hd,
.x-grid-row,
.x-grid-row,
.x-grid-cell,
.x-unselectable
{
-moz-user-select: text !important;
-khtml-user-select: text !important;
-webkit-user-select: text !important;
}
我知道您可以覆盖Ext 3中的网格行模板,如下所示,但我不知道如何在Ext 4中执行相同操作:
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>'
)
}
任何建议都非常感谢。
答案 0 :(得分:52)
您可以将enableTextSelection:true添加到viewConfig中,或者为每个网格全局应用更改:
Ext.override(Ext.grid.View, { enableTextSelection: true });
答案 1 :(得分:20)
以最Exty方式组合其中几个答案....在创建网格时,在网格的视图中将enableTextSelection设置为true。
var grid = new Ext.grid.GridPanel({
viewConfig: {
enableTextSelection: true
},
});
答案 2 :(得分:4)
您可以使用渲染器为列
添加它columns: [
{
header: "",
dataIndex: "id",
renderer: function (value, metaData, record, rowIndex, colIndex, store) {
return this.self.tpl.applyTemplate(record.data);
},
flex: 1
}
],
statics: {
tpl: new Ext.XTemplate(
'<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 :(得分:1)
我只想加入Triquis答案: 使用ExtJS 4.1.0,您还可以启用树形图的选择:
Ext.override(Ext.view.Table, { enableTextSelection: true }); // Treepanels
Ext.override(Ext.grid.View, { enableTextSelection: true }); // Grids
将此代码放在Ext.onReady()函数的早期某处或应用程序的早期。
(抱歉,我无法对Triqui的答案发表评论,因为我还没有所需的声誉。)
答案 4 :(得分:0)
另一种方法可能是在使用新的templatecolumn
时将类分配给任意html元素。这是我在将应用程序移植到extjs4时刚刚编写的列定义中的单个列。
{
text: "Notes",
dataIndex: 'notes',
width: 300,
xtype: 'templatecolumn',
tpl: [
'<span class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}"',
'style="{style}" tabIndex="0" {cellAttr}>',
'<span class="x-grid3-cell-inner x-grid3-col-{id}" {attr}>{notes}',
'</span></span>' ],
editor: {xtype:'textfield'}
}
答案 5 :(得分:0)
对于不支持启用文本选择的旧版EXTJS。以下将通过为网格单元分配新模板来工作。这适用于EXTJS 3.4.0
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>'
)
}
},
});
答案 6 :(得分:0)
您可以使用这几行代码启用网格视图的选择, 它在EXTJS 3.4中运行良好,具有IE 11和兼容模式
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>'
);
答案 7 :(得分:0)
true值不起作用,请按以下方式使用:
userSelectable:{ bodyElement:“文字” }