kendo-react icon indicating copy to clipboard operation
kendo-react copied to clipboard

Grid with Groups, Virtual Scrolling and Selection does not function properly

Open helm100 opened this issue 1 year ago • 9 comments

I'm submitting a Feature request/Bug report

  • Bug report

Similar issue: https://github.com/telerik/kendo-react/issues/1535

Current behavior

In a grid where virtual scrolling is enabled along with grouping, the GridSelectionChangeEvent contains faulty data.

Expected behavior

I expect the GridSelectionChangeEvent to point to the actual DataItem that was clicked

Minimal reproduction of the problem with instructions

Starting point: https://www.telerik.com/kendo-react-ui/components/grid/scroll-modes/virtual/#toc-using-virtualization-with-grouping The bug is observable in this minimal working example: https://codesandbox.io/p/sandbox/zen-tree-mlp4pg Different rows are selected than the one that was clicked (for each group, the index is increased by 1).

What is the motivation or use case for changing the behavior?

I would like to be able to execute custom actions when a user clicks a row in a virtual grid. The action should depend on the actual field (row + column) that was clicked by the user.

Environment

Package versions: 8.0.0

Browser:

  • Chrome (desktop)
  • Firefox version

helm100 avatar Jun 04 '24 14:06 helm100

Hello @helm100 ,

Thank you for reaching out to us. This is a known issue, and it is logged in our public repository https://github.com/telerik/kendo-react/issues/1535. Our team will do their best to fix it and when we have any progress on the fix, we will update the issue.

Please excuse us for any inconvenience caused and if we can assist you with anything else, do not hesitate to submit a ticket in our support system.

Cheers, Ivaylo

iadnonov avatar Jun 05 '24 07:06 iadnonov

It is a regression between versions 7.3.0 and 7.4.0 for the Grid and is specific to using grouping, selection, and virtualization.

For 7.3.0 it was working - https://stackblitz.com/edit/react-kenryc-hgt7wj?file=package.json

For 7.4.0 it stopped working - https://stackblitz.com/edit/react-kenryc-amrqfp?file=package.json

WissamProgress avatar Jun 10 '24 08:06 WissamProgress

Fixed in dev version 8.1.0-develop.19.

iadnonov avatar Jun 20 '24 11:06 iadnonov

I tried it out and it still doesn't show correct behavior:

  1. I forked https://stackblitz.com/edit/react-kenryc-amrqfp?file=package.json
  2. Changed Kendo packages to 8.1.0-develop.19
  3. Scrolled all the way down in the grid
  4. Clicked rows; other rows got selected

helm100 avatar Jun 24 '24 13:06 helm100

Same is the case with checkbox selection when combined with virtual scroll. The onSelectionChange event returns an incorrect row index, resulting in the selection of a different row.

https://stackblitz.com/edit/react-nigr7r?file=app%2Fapp.tsx,app%2Fshared-gd-products.json

Ticket ID: 1656732

WissamProgress avatar Jul 02 '24 08:07 WissamProgress

After further investigation and consulting with the team, I am changing the issue to a feature request. The reason is that the combination of virtual scrolling with grouting and selection is not a supported combination with the current KendoReact Grid implementation and needs additional changes to achieve this scenario. The previously provided fix is unable to resolve the issue and cannot be considered a regression.

Please excuse us for any inconvenience caused and when we have any progress, we will update the issue.

iadnonov avatar Jul 04 '24 09:07 iadnonov

How is this not a bug, but a feature request when it's a combination of features not working and there is no indication neither at compile time, nor at runtime or anywhere in the documentation that these features are not supported together?

Btw, we are using Kendo version 8.1.1 and a slightly modified version of Kendo's getSelectedState that uses local state instead of global one. The onSelectionChange event that Kendo emits seems to contain the correct startDataItem and endDataItem, but the wrong startRowIndex/endRowIndex. So we do a quick lookup by ID on the leaf data items from the groups and obtain the correct absolute indexes for startDataItem and endDataItem that we replace in the event that we pass down to getSelectedState which seems to do the trick as a work-around.

revov avatar Aug 09 '24 15:08 revov

A temporary workaround is to use the data key from the dataItem in the event:

  const onSelectionChange = (event: GridSelectionChangeEvent) => {
    const newState = {};
    newState[event.startDataItem[DATA_ITEM_KEY]] = true;
    setSelectedState(newState);
  };

https://codesandbox.io/p/sandbox/bold-dew-ydskkn?file=%2Fapp%2Fmain.tsx%3A41%2C1-45%2C5

The same approach can be used with the checkbox selection where you can append/remove items from the current selection

kdikov82 avatar Aug 21 '24 15:08 kdikov82

Also requested in Ticket ID: 1660567

filipKovachev avatar Aug 22 '24 12:08 filipKovachev