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

Restoring Grid State after data refresh

7 Answers 444 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 04 Jan 2013, 10:46 AM
Hi,

We have a grid with a couple of thousand rows of data, handlers on data change/selection change events, RowFormatting/Cell Formatting events and a number of conditional formatting rules applied.

We are trying to ensure that the user is placed back on their previously selected row after the grid data is refreshed. At the moment, we are storing the ID of the current row and after a refresh call Grid.TableElement.ScrollToRow to navigate back to the row. There is validation present to ensure that the row is still present.

The ScrollToRow seems to be performing very slowly though when the selected row is fairly far down the grid and it is difficult to track whether this is caused by a specific event firing for selection change, the formatting events, conditional formatting rules or something else, so I suspect that the ScrollToRow approach is not the ideal solution.

Is there a better way to navigate back to the previously selected row when the grid is refreshed?

Thanks,

Mark.

7 Answers, 1 is accepted

Sort by
0
Accepted
Julian Benkov
Telerik team
answered on 09 Jan 2013, 08:53 AM
Hello Mark,

In this scenario when the 'ID' of the DataBoundItem is used to find a RadGridView row reference there no any other solution than the ScrollToRow API. You can use the VScrollBar.PossitionOffset property of the TableElement to save / restore the scroll-bar position, but this solution will not work properly in cases when data is changed, sorting or filtering operation is applied.

If you continue to experience these issues, please send me a sample application with some part of your data so we can review the specific case and try to find the best solution it.

Thank you for your time and cooperation.

Regards,
Julian Benkov
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Jeff
Top achievements
Rank 1
answered on 28 Feb 2014, 05:15 PM
Hi Mark,

It may not be ideal, but one option to improve the performance of the ScrollToRow call, in your case, might be to wrap the invocation with methods to disable and enable your grid's other events.  The ScrollToRow call should, in theory, be doing nothing more than scrolling to the given row.  The grid should not be introducing any other "side effects" of scrolling; those should be handled explicitly, not accidentally.  How about something like:

DisableGridEvents();
try
{
    grid.ScrollToRow(rowIdx);
}
finally
{
    EnableGridEvents();
}

/// DisableGridEvents
private bool gridEventsEnabled = true;
private void DisableGridEvents();
{
    this.gridEventsEnabled = false;
}

private void Grid_CellFormatting(...)
{
    if (this.gridEventsEnabled)
    {
        // do the normal stuff.
    }
}

That's incomeplete, but I think you'll get the idea.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Mar 2014, 12:41 PM
Hello,

Thank you for contacting Telerik Support.

Suspending the grid events is not a recommended solution because you may encounter a situation in which the CellFormatting will be suspended when it is necessary. Another option is to keep the CurrentRow before refreshing the grid and restore it afterwards, calling the EnsureVisible method as well or restoring the RadGridView.TableElement.VScrollBar.Value.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik

DevCraft Q1'14 is here! Join the free online conference to see how this release solves your top-5 .NET challenges. Reserve your seat now!

0
Mason
Top achievements
Rank 1
answered on 21 Jan 2015, 08:37 PM
Julian,

You stated that when data is changed, sorting or filter the ScrollToRow API will  not work. Is there any solution you can recommend? It seems if you have such an API there should be a way to accommodate this. 

I have a similar issue that sorting and filtering make use of the ScrollToRow invalid. 

Regards
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Jan 2015, 02:49 PM
Hello Tim,

Thank you for writing.

According to Julian's post, the TableElement.VScrollBar.PossitionOffset property may not restore the scroll-bar position correctly when sorting or filtering operation is applied. The recommended approaches from my previous post behaves as expected on my end. However, note that you may have current row which is not visible in the view as the vertical scroll bar may be scrolled to a certain value. In this situation it would be better to keep and restore the TableElement.VScrollBar.Value. Calling the TableElement.ScrollToRow method place the specific row to be first into the view no matter if the grid is sorted or not.

If you are still experiencing any difficulties, I would recommend you to open a support thread with a sample project demonstrating the undesired behavior that you are facing. Thus, we would be able to investigate the precise case and assist you further. Thank you in advance.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Paul Dell
Top achievements
Rank 1
Iron
answered on 13 Nov 2019, 01:55 PM

I had the same issue and solved it by first restoring the VScrollBar.Value and then using the ScrollToRow method.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Nov 2019, 02:57 PM
Hello, Tel, 

Storing the TableElement.VScrollBar.Value before refreshing the grid and restoring its value after that is a suitable approach to return the vertical scrollbar to its previous location. However, have in mind that the scroll-bar's range depends on the number of rows that are loaded in RadGridView. In other words, the more rows you have, the bigger maximum the vertical scroll-bar has and vice versa. Hence, you have to be careful when setting the TableElement.VScrollBar.Value and prevent exceeding its Maximum.

Should you have further questions please let me know.

 

Regards,
Dess | Tech Support Engineer, Sr.
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
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Jeff
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Mason
Top achievements
Rank 1
Paul Dell
Top achievements
Rank 1
Iron
Share this question
or