多选&取消选择Boundlist

时间:2013-05-22 14:08:24

标签: javascript extjs extjs4 extjs4.2

我必须为表单创建自定义绑定列表,当它具有单个选择并且不取消选择时,它可以正常工作。如何告知边界列表进行取消选择和多选?

不起作用:

var mode = this.multiselect ? 'MULTI' : 'SINGLE';
var sm = bl.getSelectionModel();  // TODO 
sm.setSelectionMode(mode);
sm.allowDeselect = this.deselect;

不起作用(这是在扩展的FieldContainer中):

var bl = Ext.create('Ext.view.BoundList', {
    multiSelect: this.multiselect,
    deselect: this.deselect,
    //...

2 个答案:

答案 0 :(得分:1)

不确定您要实现的行为。多模式允许默认取消选择,而allowDeselect配置选项在这种情况下不适用。以下是Ext.selection.Model文档的引用:

allowDeselect:Boolean

允许用户取消选择DataView,List或Grid中的记录。 仅在模式为“单一”时才适用。

答案 1 :(得分:1)

如果我理解正确,您希望只需在多选中单击即可取消选择唯一选定的记录。

试试这段代码:

// Allow deselecting the only selected record in MULTI mode with a simple click.
// Note that this will only happen when allowdeselect is true
Ext.override( Ext.selection.Model, {
    selectWithEvent: function(record, e, keepExisting) {
        var me = this;

        switch (me.selectionMode) {
            case 'MULTI':
                if (e.ctrlKey && me.isSelected(record)) {
                    me.doDeselect(record, false);
                } else if (e.shiftKey && me.lastFocused) {
                    me.selectRange(me.lastFocused, record, e.ctrlKey);
                } else if (e.ctrlKey) {
                    me.doSelect(record, true, false);
                // Mod Start
                } else if (me.isSelected(record) && !e.shiftKey && !e.ctrlKey && me.selected.getCount() == 1 && me.allowDeselect) {
                    me.doDeselect(record, false);                    
                // Mod End                        
                } else if (me.isSelected(record) && !e.shiftKey && !e.ctrlKey && me.selected.getCount() > 1) {
                    me.doSelect(record, keepExisting, false);
                } else {
                    me.doSelect(record, false);
                }
                break;
            case 'SIMPLE':
                if (me.isSelected(record)) {
                    me.doDeselect(record);
                } else {
                    me.doSelect(record, true);
                }
                break;
            case 'SINGLE':
                // if allowDeselect is on and this record isSelected, deselect it
                if (me.allowDeselect && me.isSelected(record)) {
                    me.doDeselect(record);
                // select the record and do NOT maintain existing selections
                } else {
                    me.doSelect(record, false);
                }
                break;
        }
    },
});