PDA

View Full Version : Cannot unselect in Ext.View



Animal
17 Jul 2007, 1:48 AM
It is customary for Ctrl/click on a selected item to unselect that item.

Ext.View does not allow unselection. Selection is a one-way process! Once selected, the user cannot unselect anything.

I've added the following to my overrides. My additions in bold



Ext.override(Ext.View, {
onItemClick : function(item, index, e){
if(this.fireEvent("beforeclick", this, index, item, e) === false){
return false;
}
if(this.multiSelect || this.singleSelect){
if(this.multiSelect && e.shiftKey && this.lastSelection){
this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
}else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
this.unselect(item);
} else {
this.select(item, this.multiSelect && e.ctrlKey);
this.lastSelection = item;
}
e.preventDefault();
}
return true;
},

unselect : function(nodeInfo, suppressEvent){
var node = this.getNode(nodeInfo);
if(node && this.isSelected(node)){
if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
Ext.fly(node).removeClass(this.selectedClass);
this.selections.remove(node);
if(!suppressEvent){
this.fireEvent("selectionchange", this, this.selections);
}
}
}
}
});

jack.slocum
17 Jul 2007, 4:56 PM
This would be under the category "enhancement", not bug. It's a missing feature that it would make (a lot of) sense to have.

On that note, this has already been addressed in 2.0. DataView has a more rebust selection implementation.