This is a migrated thread and some comments may be shown as answers.

Setting the current grid to the first selected item

1 Answer 244 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 27 Nov 2018, 05:38 PM

I am storing the selected grid item in local storage so the state of the app can be maintained between refreshes.

Upon reloading the SPA, I want to restore the state of the grid, and that includes switching to the page where the first selected item is.

Some issues that make this impossible:

1. I do not know the page of the item, since the number of items in the grid could have changed since last load and therefore I can't use/save the page as a mechanism for showing the first selected item on reload.

2. If I use ViewChild(GridComponent) grid, then grid.data is just a collection of rows for the current page and won't show the prior selected item if the number of items in the grid has changed.

3. If I use my own collection as a mechanism for showing the first selected item (by setting the current page to the index of the selected item in my own collection divided by page size), it will not match the kendo grid's internal collection (because of sorting etc).

What is the correct way to set the grid to the first selected item between browser reloads?

1 Answer, 1 is accepted

Sort by
0
Svet
Telerik team
answered on 29 Nov 2018, 09:25 AM
Hi John,

Indeed, at the moment such feature is not available out of the box. If you have the time, please support the following feature request from our feedback portal by voting for it:
https://feedback.telerik.com/kendo-angular-ui/1360621-grid-add-api-methods-to-programmatially-scroll-to-top-and-to-scroll-to-an-item

What could be done in order to achieve the desired functionality is to store, the selected item, that we want to navigate to. Then on each reload we can get the full set of data and use the process function to apply the current Grid's state in order to produce the array, that is used by the grid. Then we can find the index of the stored item. Based on the index and the pageSize we can determine the page, where the item will be located.

Another approach would be to implement some server side logic, that provides an endpoint, that accepts a specific item and returns the page number of its occurrence. 

You may also check the following article, that discusses the first suggested approach (about a grid with virtual scrolling, the same logic would apply for grids with paging) on the following link:
https://www.telerik.com/forums/kendo-ui-grid-angular---scroll-to-selected-row

I hope this helps. Let me know in case I can provide any further assistance on this case. 

Regards,
Svetlin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
John
Top achievements
Rank 1
Answers by
Svet
Telerik team
Share this question
or