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. Image for the cookie policy date
close icon

Save and Load filters in SFDatagrid

Hi,

Is there anyway i can capture all the filters apply on the excel like filtering, stored the filters in an object, and load the object back into the filters any time i want later on?

Thanks and best regards,
Kevin


1 Reply

AN Ashok N Syncfusion Team May 13, 2014 12:43 PM UTC

Hi Kevin,

Thanks for using Syncfusion Products.

You can achieve your requirement by serializing and de-serializing FilterPredicate in sample level. We have created the sample to achieve your requirement. Please find the sample in the following link.

Sample: http://www.syncfusion.com/downloads/support/directtrac/124663/DataGridFiltering31740703.zip

In this sample we have used SerializeFilters extension method for serialization operation in that method we serialize the filter predicate each column and store in xml file. For Deserialization we use DeserializeFilters extension method, and in that method we de-serialize xml file and set the filter predicate back to grid columns.

Serialization:

private async void Button_Click_1(object sender, RoutedEventArgs e)

{

    try

    {

        var folder = KnownFolders.DocumentsLibrary;

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

        this.datagrid.SerializeFilters(storageFile);

    }

    catch (Exception)

    {

        //throw;

    }

}

 

Deserialization:

private async void Button_Click_2(object sender, RoutedEventArgs e)

{

    try

    {

        var folder = KnownFolders.DocumentsLibrary;

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

        this.datagrid.DeserializeFilters(storageFile);

    }

    catch (Exception)

    {

        //throw;

    }

}

 

Please let us know if you have any queries.

Thanks,

Ashok


Loader.
Live Chat Icon For mobile
Up arrow icon