3

I was wondering if it is possible to deselect a selected row in a ExtJS 6 grid with this selModel configuration:

selModel: Ext.create('Ext.selection.CheckboxModel', {
            mode: 'SINGLE',
            checkOnly: 'true',
            allowDeselect: true,                              
 }),

I've got the following fiddle which shows the behavior I am currently facing: https://fiddle.sencha.com/#fiddle/1h4l

It looks like the only way to deselect a row is by selecting another row, which is not what I need.

hbulens
  • 1,872
  • 3
  • 24
  • 45
  • I looks like a bug. I would report it on the Sencha forum - the allowDeselect doesn't seem to have any effect. – pagep Sep 21 '16 at 12:33
  • @pagep Thought so too. I'll submit the ticket right away. – hbulens Sep 21 '16 at 12:35
  • @hbulens Yes I tried in many possible scenario to grid but allowDeselect does'nt make any effect in EXTJS 6, Its fine ExtJS 5. Its bug. – UDID Sep 21 '16 at 12:47

2 Answers2

2

Don't directly create the selection model; use the xtype instead. Changing the selModel to this works as expected in your fiddle:

selModel: { 
  selType: 'checkboxmodel',
  mode: 'SINGLE',
  checkOnly: 'true',
  allowDeselect: true               
},
Robert Watkins
  • 2,196
  • 15
  • 17
  • That does work. I'll keep the bug report open because both approaches should be equivalent. I used Chandra Sekar's workaround but this one is an actual solution. – hbulens Sep 22 '16 at 14:59
  • The two approaches are not equivalent. When you create the checkbox manually, you skip a number of steps the the Ext.view.Table class (used by the grid) does in initialising the selection model. A good rule of thumb with ExtJS is to avoid creating objects directly if it can take an alias. – Robert Watkins Sep 22 '16 at 20:37
0
selModel: Ext.create('Ext.selection.CheckboxModel', {
        checkOnly: 'true',
        allowDeselect: true,                              
 }),

If you remove the mode:'SINGLE' then it works fine.

If you want to select one row at a time then you should check in the "beforeselect" event if any other row is selected or not.

You can get the number of checked ones by using:

var selectedRows = getSelectionModel().getSelection();
hbulens
  • 1,872
  • 3
  • 24
  • 45
Chandra Sekar
  • 302
  • 1
  • 13