Javascript 热禁用 Ext.JS 网格中的行选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3989555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hot to disable row selection in Ext.JS grid
提问by John
How do I disable row selection in an Ext.JS grid?
如何在 Ext.JS 网格中禁用行选择?
回答by ncardeli
You must set disableSelection property to true. Its value is ignored if a SelectionModel is specified.
您必须将 disableSelection 属性设置为 true。如果指定了 SelectionModel,则忽略其值。
For example:
例如:
var grid = new Ext.grid.GridPanel({
disableSelection: true,
store: new Ext.data.Store({
reader: reader,
data: xg.dummyData
}),
columns: [
{id:'company', header: "Company", width: 200, sortable: true, dataIndex: 'company'},
{header: "Price", width: 120, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
{header: "Change", width: 120, sortable: true, dataIndex: 'change'},
{header: "% Change", width: 120, sortable: true, dataIndex: 'pctChange'},
{header: "Last Updated", width: 135, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
],
viewConfig: {
forceFit: true,
// Return CSS class to apply to rows depending upon data values
getRowClass: function(record, index) {
var c = record.get('change');
if (c < 0) {
return 'price-fall';
} else if (c > 0) {
return 'price-rise';
}
}
},
width:600,
height:300,
frame:true,
title:'Framed with Checkbox Selection and Horizontal Scrolling',
iconCls:'icon-grid'
});
If you want to disable selection of some rows only, you can add a listener to the SelectionModel "beforerowselect" event and return false when you don't want a row to be selected.
如果您只想禁用某些行的选择,您可以向 SelectionModel "beforerowselect" 事件添加一个侦听器,并在您不想选择某行时返回 false。
回答by Saket Patel
use this config if you don't have a selection model for you grid
如果您的网格没有选择模型,请使用此配置
var grid = new Ext.grid.GridPanel({
disableSelection: true,
});
else you this little trick to disable selection in the RowSelectionModel
否则你这个小技巧来禁用 RowSelectionModel 中的选择
var grid = new Ext.grid.GridPanel({
selModel : new Ext.grid.RowSelectionModel({selectRow: Ext.emptyFn})
});
回答by Yanuar
you can do another trick for your grid, looks like this :
你可以为你的网格做另一个技巧,看起来像这样:
grid.getSelectionModel().lock();