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

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.


Languages

Language:C# 100.0%