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

event.dataItem is null during the onSelectionChange event of the Grid.

Open simonssspirit opened this issue 4 years ago • 2 comments

event.dataItem is null during the onSelectionChange event of the Grid.

https://www.telerik.com/kendo-react-ui/components/grid/api/GridSelectionChangeEvent/#toc-dataitem

https://stackblitz.com/edit/react-xrbucq-6xyhhx?file=app%2Fmain.jsx

simonssspirit avatar Jun 17 '21 12:06 simonssspirit

any update on it?

da1z avatar May 11 '22 00:05 da1z

As a temporary workaround, the old and the new selected states can be compared:

  const onSelectionChange = (event) => {
    const newSelectedState = getSelectedState({
      event,
      selectedState: selectedState,
      dataItemKey: DATA_ITEM_KEY,
    });
    for (const key of Object.keys(newSelectedState)) {
      if (!selectedState[key] && newSelectedState[key]) {
        let newItem = event.dataItems.find((i) => i[DATA_ITEM_KEY] == key);
        console.log(newItem);
      }
    }
    setSelectedState(newSelectedState);
  };

https://stackblitz.com/edit/react-pnvg8k-pdq3pc?file=app%2Fmain.jsx

kdikov82 avatar Jan 30 '23 20:01 kdikov82

The issue is addressed in the latest dev version and will be available in the next official version of KendoReact. Currently dataItem is available when the checkbox selection column is used. In order to have similar information for the other types of selection we provided startDataItem and endDataItem props that will provide the first and the last selected item.

zdravkov avatar May 12 '24 15:05 zdravkov