1

I'm have to make a custom boundlist to a form, it works fine when it has single select and do not deselect. How can I tell to the boundlist to do the deselect and multiselect?

Not works:

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

Not works (this is in an extended FieldContainer):

var bl = Ext.create('Ext.view.BoundList', {
    multiSelect: this.multiselect,
    deselect: this.deselect,
    //...
Eleanor
  • 358
  • 5
  • 24

2 Answers2

1

Not sure what behavior you are trying to achieve. Multi mode allows deselect by default and the allowDeselect config option is not applicable in this case. Here is a quote from Ext.selection.Model documentation:

allowDeselect : Boolean

Allow users to deselect a record in a DataView, List or Grid. Only applicable when the mode is 'SINGLE'.

Amit Aviv
  • 1,816
  • 11
  • 10
  • Yes, I know, I set both properties `true`, but deselect and/or multiselect doens't work :( (ExtJS 4.2) – Eleanor May 23 '13 at 06:38
  • (or deselect can be true while multi is false... ) – Eleanor May 23 '13 at 06:48
  • this is the history: http://stackoverflow.com/questions/16669946/using-boundlist-as-widget – Eleanor May 23 '13 at 13:42
  • 1
    I set up a [fiddle](http://jsfiddle.net/amitaviv99/dHZc6/) with a field container and bound list. It works fine with multiSelect (like the second option in your post). It also works with multiSelect=false, and allowDeselect=true. So, your second option looks good except that the "deselect" config should be "allowDeselect". If you post your full container definition, we might understand the problem. – Amit Aviv May 23 '13 at 15:27
  • Thx for all helps, it works. I have just one difficulty to make it in mvc, but I try :) – Eleanor May 24 '13 at 07:19
1

If I understand correctly, you want to be able to deselect the only selected record with a simple click in multi select.

Try this code:

// 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;
        }
    },
});
Izhaki
  • 23,372
  • 9
  • 69
  • 107