Different types of "selecting" a row in grid

Hello everyone,

i’m evaluating the grid element and i’m wondering how to distinguish between selecting a row via the check box and just clicking the row (which is also a “select” because it gets highlighted) when beeing in the multi select mode.

The documentation says there is only the “selected-items-changed” event and when being in multi select mode, it’s only fired when i select a row by checking it’s checkbox and not when just clicking the row. When being in single select mode, it fires when just clicking on the row.

But how to catch these different types of selecting a row when being in multi select mode?

Regards,
Michael

The highlight you get when just clicking on a cell is the indication of Grid “internal focus” on that row. This is information not available on the server-side (except in the case of events like ItemClickListener, which contains the row and column that was just clicked). You can modify your multi-selection model to select with mouse click (see:
related blog post
) or use Table like selection provided in my
GridExtensionPack
add-on. If this sounds too tricky, you can do a simple ItemClickListener that selects or deselects the clicked row.

HTH
//Teemu

Ah, sorry. Didn’t notice this was related to the Elements version of the Grid :slight_smile: Just ignore what I said.

Hehe, thx at all Teemu.

So is there any solution for the elements version of the vaadin grid?

Hi Michael,

The elements version of the grid works the same as the Java framework version (same underlying implementation), and the other type of “selection” if just the focus for keyboard navigation. In multi select mode, you only get the selection change events when toggling the checkboxes.

There’s an open enhancement issue about listening to other events on the rows, such as clicks:
https://github.com/vaadin/vaadin-grid/issues/144

Thx Jounin. I hope the enhancement issue will find it’s way into development soon as this is a very basic funcionality which a BI grid should offer :wink:

Hello Jouni,

has there been any progress on this issue in the last months? Maybe it’s a planned feature for the current Grid 2.0 rewrite?

Regards,
Michael

P.S.: thx for your talk at the Polymer Summit :slight_smile:

Hi Micheal,

Sorry for the late response, I didn’t remember to check the forum lately (and it’s quite unfortunate that our forum software doesn’t have support for subscribing a whole category, only single topics).

No real progress on this for grid 1.x, but 2.0-pre should already support this, where you should be able to listen for cell clicks. I’ll find you an example about this, just a sec.

Here are the latest demos for grid 2.0.0-pre.2:
https://cdn.vaadin.com/vaadin-core-elements/preview/vaadin-grid/demo/selection.html

You can see in the last example how to use the cell click events, and update the selection using that. So you should be able to combine the first and last examples and get the behavior you need.

Great! Looking forward to the release of 2.0 :slight_smile:

Thank you!

Hello Jouni,

long time since my last post here, but I’m still struggling with this issue.

I started using the 3.0.0 beta grid and trying to implement a selection behavior like it’s know from nearly all Windows applications / lists. Most popular example is the Windows Explorer.

Clicking items with “Ctrl” pressed, you get the multiselection. Clicking a single item without “Ctrl” pressed, you get the single selection and all eventually present multiselections are gone.

How can I achieve this behavior with the elements grid 3? I figured out getting single or multiselect easily, no deal, but combining both seems not possible for me.

Regards,
Michael

To be a little more precise: getting the selections itself is not the problem. “activeItem” contains the last clicked row item, and “selecteItems” contains all selected items. That’s perfect!

But:

  1. When in multiselect mode, there is no visible difference between all selected rows and the “current” (last) selected row (with “auto-select” option enabled) .
  2. Also I don’t know any way how to decide if the user wants so select one more row for multiselect, or if he wants to go back to a single selection. Thats what’s done in Windows with pressing “Ctrl” or not. In “vaadin-grid-cell-click-behavior.html”, the “_onClick” functions knows it because it gets the “ctrlKey” property from the Event, but down to the “_activeItemChanged(activeItem)” observer, there is no (known) way to know if ctrl was pressed or not. Or is there any way?

Could you implement what you want by setting a property on keydown and then clearing it on keyup.

So on (ctl) keydown you set multi = true and on (ctl) keyup you set multi=false.

Then when you are evaluating activeItem changed you check the value of “multi”