热以禁用Ext.JS网格中的行选择

Joh*_*ohn 8 javascript extjs

如何在Ext.JS网格中禁用行选择?

nca*_*eli 8

您必须将disableSelection属性设置为true.如果指定SelectionModel,则忽略其值.

例如:

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'
});
Run Code Online (Sandbox Code Playgroud)

如果要仅禁用某些行的选择,可以向SelectionModel"beforerowselect"事件添加侦听器,并在不希望选择行时返回false.

  • "beforerowselect"效果很好!代码的粗略例子:`listeners:{beforeselect:{fn:function(me,record,index,eOpts){if(record.data.status!="Ready for selection"){return false; }.} (3认同)