We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

What is the best way to refresh sfDataGrid UI?

Thread ID:

Created:

Updated:

Platform:

Replies:

133041 Oct 5,2017 09:31 AM Oct 9,2017 07:35 AM Xamarin.Forms 3
loading
Tags: SfDataGrid
Gunnar Carlson
Asked On October 5, 2017 09:31 AM

From a performance point of view - what is the best way to refresh a grid on the display?

I have en app where the user can select different skins and the skinning of the datagrid is implemented on both grid and cell levels:

grid (for headers and gridlines):

GridStyle="{StaticResource gridColors}"

cell:

<syncfusion:GridTextColumn.CellStyle>
    <Style TargetType="syncfusion:GridCell">
        <Setter Property="Foreground"
            Value="{Binding UserData[0].TextColor, Mode=OneWay}" />
        <Setter Property="BackgroundColor"
            Value="{Binding UserData[0].BackgroundColor, Mode=OneWay}" />
    </Style>
</syncfusion:GridTextColumn.CellStyle>


All of this works exactly as I want it to, no problem. But when a user select a new skin, I need to initiate a refresh of the complete grid to apply the new skin, and the only way I have found to do this is through:

dataGrid.ItemsSource = null;
dataGrid.ItemsSource = data.Items;

This also do exactly what I want it to do, but the performance is rather poor.  Is there any better way to initiate a refresh of the grid style? (The content of the grid is unchanged, only the style is changed)


Ashok N [Syncfusion]
Replied On October 6, 2017 08:56 AM

Hi Gunnar, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your query and you can refresh the view by using DataRowBase.UpdateRow methods. Please refer the below code example  
 
private void Button_Clicked(object sender, EventArgs e) 
{ 
    var items = dataGrid.GetRowGenerator().Items; 
    foreach (var item in items) 
    { 
        item.UpdateRow(); 
    } 
} 
 
Regards, 
Ashok 


Gunnar Carlson
Replied On October 6, 2017 06:21 PM

I tried the method you suggested and it doesn't do anything visible. Maybe the UpdateRow method tries to update the data content on the row, but since the content isn't changed, no visible change is made when the method is called. The only things that should be updated is the styling, and I can't see that UpdateRow do that.

BUT...I have found a solution through a tip you gave in one of my other questions.

Since a row in my case is an array of the class UserData, all I had to do was to raise a PropertyChanged event for "UserData"

foreach (var item in data.Items)
{
       item.RaisePropertyChanged("UserData");
}
dataGrid.GridStyle = new GridColors();

The last line is to trigger an update of GridStyle (I have a gridstyle class defining some of the colors.)

With those two additions, I can make the datagrid apply the new skin much faster than when i re-bound the ItemSource. Problem solved.


Vimal Prabhu Manohkaran [Syncfusion]
Replied On October 9, 2017 07:35 AM

Hi Gunnar,

Thanks for the update. Since you are using CellStyles for the GridCell, the approach you have mentioned above is the recommended and efficient approach. So we recommend you to stick on to the same.

Regards,
Vimal Prabhu
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;