Articles in this section
Category / Section

How to Save and Reload the filters of DataGrid in UWP application?

4 mins read

SfDataGrid allows you to save and load the grid settings using the SfDataGrid.Serialize and SfDataGrid.Deserialize methods. You can customize this process 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.

You can enable or disable the serialization of filters in SfDataGrid by setting SerializationOptions.SerializeFiltering property as illustrated in the following code example.

Serialization in WPF platform

C#

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

Serialization in Silverlight platform

C#

using System.IO.IsolatedStorage;
private void serialization_Click(object sender, RoutedEventArgs e)
{
    if (SfdataGrid == null) return;
    var serializationOptions = new SerializationOptions()
    {
        SerializeFiltering = true,
    };
    using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream ISFstream = ISF.OpenFile("DataGrid.xml", FileMode.Create))
        {
            SfdataGrid.Serialize(ISFstream, serializationOptions);
        }
    }
}

Serialization in WinRT platform

C#

using Windows.Storage;
private async void serialization_Click(object sender, RoutedEventArgs e)
{
    var folder = KnownFolders.DocumentsLibrary;
    var storageFile = await folder.CreateFileAsync("DataGrid.xml", CreationCollisionOption.ReplaceExisting);
    var options = new SerializationOptions() 
    { 
        SerializeFiltering=true,
    };
    options.SerializeFiltering = true;
    this.SfdataGrid.Serialize(storageFile, options);
}

In the same way, you can enable or disable deserialization of serialized filters to SfDataGrid by setting DeserializationOptions.DeserializeFiltering property as illustrated in the following code example.

Deserialization in WPF platform

C#

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

Deserialization in Silverlight platform

C#

using System.IO.IsolatedStorage;
private void Deserialization_Click(object sender, RoutedEventArgs e)
{
    if (SfdataGrid == null) return;
    var deserializationOptions = new DeserializationOptions()
    {
        DeserializeFiltering = true,
    };
    using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream ISFstream = ISF.OpenFile("DataGrid.xml", FileMode.Open))
        {
            SfdataGrid.Deserialize(ISFstream, deserializationOptions);
        }
    }
}

Deserialization in WinRT platform

C#

using Windows.Storage;
private async void Deserialization_Click(object sender, RoutedEventArgs e)
{
    var folder = KnownFolders.DocumentsLibrary;
    var storageFile = await folder.GetFileAsync("DataGrid.xml");
    var options = new DeserializationOptions() 
    { 
        DeserializeFiltering=true,
    };
    options.DeserializeFiltering = true;
    this.SfdataGrid.Deserialize(storageFile, options);
}

 

Conclusion

I hope you enjoyed learning about how to save and reload the filters UWP DataGrid.

You can refer to our UWP DataGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our UWP DataGrid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied