【问题标题】:Hot to disable row selection in Ext.JS grid热禁用 Ext.JS 网格中的行选择
【发布时间】:2010-10-21 16:12:49
【问题描述】:

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

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    您必须将 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'
    });
    

    如果您只想禁用某些行的选择,您可以在 SelectionModel 的“beforerowselect”事件中添加一个侦听器,并在您不想选择某行时返回 false。

    【讨论】:

    • 谢谢,但如果我也有 selectionModel 怎么办。
    • 您要禁用选择所有行还是部分行?
    • 如果要禁用所有行,则不要指定 SelectionModel。拥有一个 SelectionModel 并禁用所有行的选择是没有意义的。
    • @ncardeli 你能给我举个例子,使用“beforerowselect”事件禁用某些行的选择吗?
    • "beforerowselect" 效果很好!粗略的代码示例:listeners: { beforeselect: { fn: function(me, record, index, eOpts) { if (record.data.status != "Ready for selection") { return false; } } } }
    【解决方案2】:

    如果您的网格没有选择模型,请使用此配置

    var grid = new Ext.grid.GridPanel({
        disableSelection: true,
    });
    

    这个小技巧可以禁用 RowSelectionModel 中的选择

    var grid = new Ext.grid.GridPanel({
        selModel : new Ext.grid.RowSelectionModel({selectRow: Ext.emptyFn})
    });
    

    【讨论】:

      【解决方案3】:

      你可以为你的网格做另一个技巧,看起来像这样:

      grid.getSelectionModel().lock();
      

      【讨论】:

        猜你喜欢
        • 2010-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多