2

I have a grid with checkbox selection to allow multiple rows selection.

Ext.define("app.view.grid.MyGrid", {
  extend: "Ext.grid.Grid",
  xtype: "app.MyGrid",

  viewModel: "Grid",

  selectable: {
    rows: true,
    checkbox: true,
  },

But now, how can I get all the selected rows? If I use grid.getSelection(), it only shows the latest selected row. I saw many answers using grid.getSelectionModel().getSelection() but this works on Classic toolkit, I am using 7.4 Modern.

If I try, it gives me getSelectionModel() is not a function and this method is not available anymore : https://docs.sencha.com/extjs/7.4.0/modern/Ext.grid.Grid.html#event-select

Thank you

RynnHeldeD
  • 51
  • 6

1 Answers1

1

Try grid.getSelections(), in modern toolkit it should return an array with the selected items.

Peter Koltai
  • 8,296
  • 2
  • 10
  • 20
  • It works! Damn, I can't believe it was so easy. Could you tell me how you found this? I took a look at the API doc but there is no "getSelectionS()" plural method listed, only "getSelection()" in singular. Thanks – RynnHeldeD Dec 06 '21 at 08:38
  • If you search for `getSelection` in modern toolkit documentation, not on the first page, but later you will see two classes with `getSelections`: `Ext.dataview.selection.Model` and `Ext.mixin.Selectable`. One of these is used in grid (I don't know which), but somehow it is missing from the grid's documentation. – Peter Koltai Dec 06 '21 at 09:38
  • I don't see the `Ext.mixin.Selectable` in the `Grid` mixins and inherited mixins list, so unless the doc is incomplete, I think it relies on `Ext.dataview.selection.Model`. Thank you for pointing it out! – RynnHeldeD Dec 06 '21 at 14:30
  • You are welcome, I think it is a documentation problem. – Peter Koltai Dec 06 '21 at 16:04