Skip to content

This example describes how to save and reload filters in winui datagrid.

Notifications You must be signed in to change notification settings

SyncfusionExamples/How-to-save-and-reload-filters-in-winui-datagrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to save and reload filters in WinUI DataGrid?

About the sample

This example describes how to save and reload filters in WinUI DataGrid.

WinUI DataGrid (SfDataGrid) allows to save and load the grid settings using the SfDataGrid.Serialize and SfDataGrid.Deserialize methods. This process can be customized by passing SerializationOptions and DeserializationOptions as parameters to these methods. SerializationOptions and DeserializationOptions contains a set of properties that is used to customize the serialization/deserialization process.

Filters applied to the DataGrid can be saved by enabling the serialization of filters by setting SerializationOptions.SerializeFiltering property as illustrated in the following code example.

private void OnSerializeClicked(object sender, RoutedEventArgs e)
{
      if (dataGrid == null) return;
      var serializationOptions = new SerializationOptions()
      {
            SerializeFiltering = true,
      };
      using (var file = File.Create("DataGrid.xml"))
      {
            dataGrid.Serialize(file, serializationOptions);
      }
}

In the same way, the deserialization of serialized filters can be performed by enabling DeserializationOptions.DeserializeFiltering property as illustrated in the following code example.

private void OnDeserializeClicked(object sender, RoutedEventArgs e)
{
      if (dataGrid == null) return;
      var deserializationOptions = new DeserializationOptions()
      {
           DeserializeFiltering = true,
      };
      using (var file = File.Open("DataGrid.xml", FileMode.Open))
      {
           if (deserializationOptions.DeserializeFiltering == true)
           {
               dataGrid.Deserialize(file, deserializationOptions);
           }
      }
}

Serialization and Deserialization applied in SfDataGrid

Take a moment to peruse the WinUI DataGrid - Serialization and Deserialization documentation, where you can find about serialization and deserialization with code examples.

Requirements to run the demo

Visual Studio 2019 and above versions

About

This example describes how to save and reload filters in winui datagrid.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages