Find item in grid and show page containing it

1 Answer 138 Views
Grid
Marc
Top achievements
Rank 1
Marc asked on 03 Apr 2023, 01:10 PM

I have a grid using paging and sorting features. When a user edit a record (I am using an edit form that show an edit form) and he changed the value from the sorted column, the item is no more visible in the current page since it moved in another page according to the sorting feature.

My question how can I find in which page my item is now on, and to programmatically select that page so my item will stay in the current view after edition.

Thanks

Marc
Top achievements
Rank 1
commented on 03 Apr 2023, 02:28 PM

I know how to set the current page using the Page attribute, but don't know how to know on which page an item is located according to the current sort.

1 Answer, 1 is accepted

Sort by
1
Dimo
Telerik team
answered on 06 Apr 2023, 10:00 AM | edited on 06 Apr 2023, 10:01 AM

Marc - 

Usually, this task will require a manual calculation in the app.

What you can use from our product to help you is the ToDataSourceResult() method.

  1. Get the Grid state
  2. Create a new DataSourceRequest instance
  3. Populate all relevant DataSourceRequest properties, based on the information from the Grid state. Do not include paging settings.
  4. Execute ToDataSourceResult() over the whole dataset and pass the DataSourceRequest object as an argument. In this way you will get all items in the current sorted and filtered state, but without paging.
  5. Get the item index and calculate the page number.
  6. Go to that page.

If this approach is not practical, because the total number of items is too large to load in memory, then implement some custom algorithm that will perform better.

Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or