PDA

View Full Version : Ext.view.View with simpleSelect true, to have everytime at least one item selected



vadimv
3 Jan 2012, 4:53 AM
What's the best approach to have in view at least one item selected in SIMPLE mode ?, for example if the dataview has only one item selected and the user clicks on it, the item is not deselect - no changes in selection, but if there are more selected, then deselection works (also I have now deselectOnContainerClick set to false)? thx for any help

mitchellsimoens
3 Jan 2012, 6:20 AM
I would listen to the beforeitemclick and it if matches the currently selected item, return false.

mitchellsimoens
3 Jan 2012, 6:20 AM
note... there is an isSelected method on the View

vadimv
3 Jan 2012, 8:44 AM
note... there is an isSelected method on the View
ha....it seems that in beforeitemclick, isSelected(Ext.data.Model (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Model)) returns false, and isSelected(HTMLElement) returns true, at the same time, and getSelectionModel().getSelection() has the record, it's strange how isSelected works. I think it lacks the piece of code where is needed to check if it's record or node:


// in AbstractView
isSelected : function(node) {
// TODO: El/Idx/Record
var r = this.getRecord(node);
return this.selModel.isSelected(r);
}

'cause in case of record, getRecord returns undefined(Ext.getDom doesn't support arguments of Ext.data.Model).
My solution at your suggestion:


beforeitemclick: function(view, record,item){
var selections = view.getSelectionModel().getSelection();
if(selections.length == 1 && (selections[0].internalId == record.internalId)){
return false;
}
}

I think that "selections[0].internalId == record.internalId" is the same as isSelected(record), but faster.