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.
Syncfusion Feedback

How to retain the SfDataGrid properties when changing the data source?

SfDataGrid have a support for retaining the old values such as sorting and grouping when reloading the SfDataGrid. It can be achieved by setting SfDataGrid.AutoGenerateColumnsMode as other than ResetAll.

When you change ItemsSource for SfDataGrid, then the columns are generated on the basis of option set for SfDataGrid.AutoGenerateColumnsMode.

None:

  • Stores only the columns that are defined in SfDataGrid.Columns collection.
  • When changing the ItemsSource, the grouping and sorting for explicitly defined SfDataGrid.Columns alone will be retained.

 

Reset:

  • Retains the columns defined explicitly in the application level and creates columns newly for all the other properties in a data source.
  • When changing the ItemsSource, the grouping and sorting for explicitly defined SfDataGrid.Columns alone will be retained.

 

RetainOld:

  • When changing the ItemsSource, creates columns for all fields in a data source when the Grid does not have any explicit definition for columns.
  • When columns are defined explicitly, then the defined columns alone are retained and new columns are not created.
  • Similarly, when changing the ItemsSource and when the Grid have any explicit definition for columns, the grouping and sorting are retained as it is.

public partial class MainPage : ContentPage

{

        private SfDataGrid dataGrid;

        private ViewModel viewModel;

        public MainPage()

        {

            InitializeComponent();

            dataGrid = new SfDataGrid();

            viewModel = new ViewModel();

            dataGrid.ItemsSource = viewModel.OrdersInfo;

            dataGrid.AutoGenerateColumnsMode = AutoGenerateColumnsMode.RetainOld;

            this.Content = dataGrid;

        }

}

 

SmartReset:

  • Retains the columns defined explicitly in application level and the columns with MappingName identical to the properties in the new data source.
  • Creates columns newly for all the other properties in the data source.
  • Similarly, it retains the grouping and sorting of the columns that are defined explicitly in application level and the columns with MappingName identical to the properties in new data source.

 

ResetAll:

  • When changing the ItemsSource, the columns for the previous data source are cleared and the columns will be created newly for the new data source.
  • Even when columns are explicitly defined it does not consider the defined columns and creates the column based on the underlying collection.
  • Further, when changing the ItemsSource, the grouping and sorting for all the columns will be cleared.

 

Sample Link:

How to retain old values of SfDataGrid when reloading/re-binding SfDataGrid?

Article ID: Published Date: Last Revised Date: Platform: Control: Product Version:
7787 06/22/2017 06/22/2017 Xamarin.Forms SfDataGrid 13.4.0.53
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon 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.Close Icon