Save scroll position

I have a sfdatagrid (a) that users can scroll vertically. When users do actions on another sfdatagrid (b) it causes a refresh of the data in sfdatagrid (a) and it defualts back to the the top of the scroll. 

Can we save the current scroll postion and reset it?

3 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team November 19, 2020 10:41 AM UTC

Hi Martin,  

Thanks for contacting Syncfusion support.  

We are able understand your requirement. We are little unclear about the action o DataGrid B that moves scroll bar in the DataGrid A to top. Kindly share details about the action on DataGrid B or the code snippet that changes the scroll bar position in DataGrid A. It will be helpful for us to understand your exact scenario and to provide a prompt solution at earlier.  

Regards, 
Mohanram A. 



MA Martin November 19, 2020 10:56 AM UTC

Hi Mohanram,

I have realised that the scroll position is ressting to the top because after the changes from sfdatagrid(b) are commited back to the databse, the datatable for sfdatagrid(a) is refreshed but as their are groupings on the sfdatagrid(a) that all groupings start as closed and then i loop through and open any groups the user previously has open, without the groupings the scroll position remains constant.

I have logged another ticket (159865) with regards best practice to commit data back to the datatable so not having to refresh the entire datatable from the database each time as the methid i used previously appeared extremely inefficient and was not always successfull in updating to the sfdatagrid.


MA Mohanram Anbukkarasu Syncfusion Team November 20, 2020 01:24 PM UTC

Hi Martin,   

Thanks for the update.  

We have prepared a sample to replicate your scenario based on the provided details to maintain the scrollbar position when the DataGrid is grouped by a column and its DataSource is refreshed and the same group is added again as shown in the following code example.  

Code example :  

private void button1_Click(object sender, EventArgs e) 
{ 
    var scrollValue = this.sfDataGrid1.TableControl.ScrollRows.ScrollBar.Value; 
    this.sfDataGrid1.DataSource = new OrderInfoCollection().OrdersListDetails.Where(x => x.CustomerID != "FRANS"); 
    this.sfDataGrid1.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "Quantity" }); 
    this.sfDataGrid1.TableControl.ScrollRows.ScrollBar.Value = scrollValue; 
    this.sfDataGrid1.TableControl.UpdateScrollBars(); 
} 



Please have a look at this sample and the video demo and revert to us with details if we have misunderstood your requirement.  

Regards, 
Mohanram A. 


Marked as answer
Loader.
Up arrow icon