[Solved] How to Scroll Into View and Highlight Row in Grid

2 Answers 154 Views
Grid
Layla
Top achievements
Rank 1
Layla asked on 05 May 2025, 07:58 PM | edited on 07 May 2025, 03:46 PM

Hey Team!

We're looking to implement a scroll into view for our Kendo grid using Typescript. This example is similar to what we are looking to do when the grid first loads. https://www.telerik.com/kendo-react-ui/components/grid/scroll-modes/scroll-into-view 

Is it possible to change the background color of the row once it scrolls to the target row?

Thanks in advance!

2 Answers, 1 is accepted

Sort by
0
Accepted
Vessy
Telerik team
answered on 07 May 2025, 03:47 PM

Hi, Layla,

The functionality demonstrated in the linked demo of the Grid is achieved with the `scrollIntoView` method which aims to scroll to the n-th child of an HTML container and cannot work with the dataItems bound to the Grid Row objects. If you implement a logic finding the index of the row containing the target data, though, you can execute the `scrollIntoView` logic from the linked demo once the Grid is loaded through the useEffect hook like follows:

  const [targetRowIndex, setTargetRowIndex] = React.useState(20);

  React.useEffect(() => {
    if (gridRef.current) {
      gridRef.current.scrollIntoView({ rowIndex: targetRowIndex });
    }
  });

I hope this helps.

Kind regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Layla
Top achievements
Rank 1
commented on 07 May 2025, 10:06 PM

Hi Vessy,

Thank you for your response. When I try to import GridHandle, I get an error:

Module '"@progress/kendo-react-grid"' has no exported member 'GridHandle'.ts(2305)

It looks like we are using "@progress/kendo-react-grid": "^5.16.1". Is the scroll into view functionality still possible with this older version? 

 

Vessy
Telerik team
commented on 09 May 2025, 01:34 PM

Hi, Layla,

Yes, you should be able to use the scroll into view functionality in the used by you version as well. You can try removing the GridHandle import and replacing its usage with <any> (in case you are using Typescript):
https://stackblitz.com/edit/react-tpwhyp4w-dzpzevcz?file=package.json,app%2Fapp.tsx 

0
Jie
Top achievements
Rank 3
Iron
Iron
Iron
answered on 06 May 2026, 03:37 PM | edited on 06 May 2026, 03:37 PM

Hi,

I am implementing a logic to use the `SelectDescriptor` to get the ID of the selected row. Then find the index 

const rowIndex = dataResult.data.findIndex((item) => item.ID === selectedId)

This works well when the grid is not grouped, but won't work if it is grouped. Because the dataResult.data has a nested data structure, not a simple array anymore.

Does KendoReact provide a utility function to find the index for grouped data?

 

Thanks,

Jie

Vessy
Telerik team
commented on 08 May 2026, 12:28 PM

Hi, Jie,

When the Grid has grouping applied, `dataResult.data` returns an array of `GroupResult` objects from `@progress/kendo-data-query`. Each `GroupResult` has an `items` property that holds either the actual data rows or nested `GroupResult` objects (for multi-level grouping). A flat `Array.findIndex` on the top-level array will therefore not find rows that live inside those groups.

KendoReact does not currently expose a public utility function for flattening this grouped structure. A small recursive helper achieves the same result and works regardless of grouping depth, though:

import { GroupResult } from '@progress/kendo-data-query';

function flattenGroupedData(data: any[] | GroupResult[]): any[] {
  return data.reduce<any[]>((acc, item) => {
    if (item.items !== undefined) {
      // GroupResult — recurse into nested items
      return acc.concat(flattenGroupedData(item.items));
    }
    acc.push(item);
    return acc;
  }, []);
}
This helper can then be used in place of `dataResult.data` when looking up the row index:
const flatItems = flattenGroupedData(dataResult.data);
const rowIndex = flatItems.findIndex((item) => item.ID === selectedId);
    Jie
    Top achievements
    Rank 3
    Iron
    Iron
    Iron
    commented on 13 May 2026, 02:37 PM

    Thanks a lot, that works in general. I needed to add two placeholder rows when flattening, one for the group header row, one for the footer row, also need to check whether the group is expanded or not.
    Tags
    Grid
    Asked by
    Layla
    Top achievements
    Rank 1
    Answers by
    Vessy
    Telerik team
    Jie
    Top achievements
    Rank 3
    Iron
    Iron
    Iron
    Share this question
    or