如果我理解正确,您希望能够通过在多选中单击来取消选择唯一选定的记录。
试试这个代码:
// 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;
}
},
});