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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to maintain or serialize, de-serialize the column order and width when you navigate page?

How to maintain or serialize, de-serialize the column order and width when you navigate page?

You can maintain the SfDataGrid settings like column order, column width, sorting, grouping and etc. when navigating between page by using serialization and deserialization feature.

You can save the SfDataGrid settings in the file by using the SfDataGrid.Serialize method when you navigate to other pages. You can customize the serialization operation by setting SerializationOptions.

C#:

protected async override void OnNavigatedFrom(NavigationEventArgs e)

        {

            var folder = KnownFolders.DocumentsLibrary;

            try

            {

                var storageFile = await folder.CreateFileAsync("DataGrid.xml", CreationCollisionOption.ReplaceExisting);

                var options = new SerializationOptions();

                options.SerializeColumns = true;

                this.SfdataGrid.Serialize(storageFile, options);

            }

            catch (Exception)

            {

            }

            base.OnNavigatedFrom(e);

        }

 

Then you can de-serialize the SfDataGrid setting from the saved file by using SfDataGrid.Deserialize method when you navigate to the same page again. You can customize the de-serialization operation by setting DeserializationOptions.

 

 

 

 

 

C#:

protected async override void OnNavigatedTo(NavigationEventArgs e)

        {

            //De-serializing the DataGrid when moving to current page

            var folder = KnownFolders.DocumentsLibrary;

            try

            {

                var storageFile = await folder.GetFileAsync("DataGrid.xml");

                if (storageFile != null)

                {

                    var options = new DeserializationOptions();

                    options.DeserializeColumns = true;

                    this.SfdataGrid.Deserialize(storageFile, options);

                    await storageFile.DeleteAsync();

                }

            }

            catch (Exception)

            {

            }

            base.OnNavigatedTo(e);

        }

 

Note: The above code snippet is applicable only for WinRT platform. For WPF, you can use the same method to maintain the SfDataGrid settings when closing and opening the application.

 

Samples

WPF

WRT

UWP

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
5548 11/03/2015 02/05/2016 WinRT SfDataGrid 4.5 12.3.0.36
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