PDA

View Full Version : Multiselect in Ext.view.View



JavaDirk
15 Mar 2020, 10:44 PM
Hello community,

I want my Ext.view.View to have multiselection. I have read the documentation about it and it seems to me that I have to configure a selectionModel on the view, something like this:


view.setSelectionModel(new Ext.selection.DataViewModel(
{
store: view.getStore(),
mode: 'MULTI',
}));

But if I want to select multiple entries with the mouse and Shift or CTRL, the view selects only the item I clicked on.
What am I doing wrong?

Thank you very much, JavaDirk

JavaDirk
19 Mar 2020, 1:39 AM
After several days, I figured it out myself. You can set the selectionModel like this:


Ext.define('MyView',
{
extend: 'Ext.view.View',

selectionModel:
{
mode: 'MULTI'
},


If the situation is a little more complicated (like mine), you can set it in the initComponent:


initComponent: function ()
{
this.setSelectionModel(Ext.create('Ext.selection.DataViewModel', {
mode: this.isMultipleSelectionAllowed() ? 'MULTI' : 'SINGLE',
listeners:
{
beforeselect: (t, record, index) =>
{
return this.onBeforeSelect(record);
}
}
}));

this.callParent();


Setting the selectionModel attribute in initComponent before this.callParent() leads to an JS error:


initComponent: function ()
{
this.selectionModel = {
mode: this.isMultipleSelectionAllowed() ? 'MULTI' : 'SINGLE',
listeners:
{
beforeselect: (t, record, index) =>
{
return this.onBeforeSelect(record);
}
}
};


Hope, this helps anyone.