DataFilter Persisted

5 posts, 0 answers
  1. Zack
    Zack avatar
    112 posts
    Member since:
    Jun 2012

    Posted 30 Jan 2013 Link to this post

    Is it possible to persist a RadDataFilter and all of its filter descriptors?

    We have a large application with many controls and just need to persist the datafilter within it.
    We tried some user submitted coded to iterate filter descriptors but it constantly has issues with different member types...
    Can the persistence framework save our filter and all of its descriptors so we can reload it and reattach binding to the gridview it filters?
  2. Zack
    Zack avatar
    112 posts
    Member since:
    Jun 2012

    Posted 30 Jan 2013 Link to this post

    I think I found the basic solution in one of your Silverlight forums:
    ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadDataFilter), new FilterDescriptorCustomPropertyProvider());

    What would be the best way to save and load as an xml string with persistence framework?

    Doing it like this for now:

    //************************************* XAML

    <telerik:RadDataFilter Name="datafilter" Grid.Row="1" telerik:PersistenceManager.StorageId="datafilter"/>

    //*********** Init with control/window

    ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadDataFilter), new FilterDescriptorCustomPropertyProvider());


    //*************** Methods to save/pull as xml string

            private void Save(object sender, RoutedEventArgs e)
            {
                PersistenceManager manager = new PersistenceManager();
                using (Stream s = manager.Save(datafilter))
                {
                    s.Seek(0, SeekOrigin.Begin);
                    StreamReader r = new StreamReader(s);
                    xml = r.ReadToEnd(); //xml saved to db
                }
            }

            private void Load(object sender, RoutedEventArgs e)
            {
                using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml))) //xml pulled from db
                {
                    PersistenceManager manager = new PersistenceManager();
                    stream.Position = 0L;
                    manager.Load(datafilter, stream);
                }
            }

    //**************  Proxy class

        public class FilterDescriptorCustomPropertyProvider : ICustomPropertyProvider
        {
            public CustomPropertyInfo[] GetCustomProperties()
            {
                return new CustomPropertyInfo[]
                {
                    new CustomPropertyInfo("LogicalOperator", typeof(FilterCompositionLogicalOperator)),
                    new CustomPropertyInfo("FilterDescriptors", typeof(CompositeFilterDescriptorCollection)),
                };
            }

            public void InitializeObject(object context)
            {
                RadDataFilter filter = context as RadDataFilter;
                filter.FilterDescriptors.Clear();
            }

            public object InitializeValue(CustomPropertyInfo customPropertyInfo, object context)
            {
                return null;
            }

            public object ProvideValue(CustomPropertyInfo customPropertyInfo, object context)
            {
                RadDataFilter filter = context as RadDataFilter;
                if (customPropertyInfo.Name == "LogicalOperator")
                {
                    return filter.ViewModel.CompositeFilter.LogicalOperator;
                }
                if (customPropertyInfo.Name == "FilterDescriptors")
                {
                    return filter.FilterDescriptors;
                }
                return null;
            }

            public void RestoreValue(CustomPropertyInfo customPropertyInfo, object context, object value)
            {
                RadDataFilter filter = context as RadDataFilter;

                if (customPropertyInfo.Name == "LogicalOperator")
                {
                    filter.ViewModel.CompositeFilter.LogicalOperator = (FilterCompositionLogicalOperator)value;
                }
                if (customPropertyInfo.Name == "FilterDescriptors")
                {
                    CompositeFilterDescriptorCollection filters = value as CompositeFilterDescriptorCollection;
                    if (filter != null)
                    {
                        foreach (var item in filters)
                        {
                            filter.FilterDescriptors.Add(item);
                        }
                    }
                }
            }
        }

  3. UI for WPF is Visual Studio 2017 Ready
  4. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 04 Feb 2013 Link to this post

    Hi Zack,

    The approach you've chosen is correct. Basically the RadPersistenceFramework needs a CustomPropertyProvider to understand how to persist complex controls like the RadDataFilter. In the CustomPropertyProvider, you need to set the list of properties that have to be persisted by the framework. This logic should be placed in the GetCustomProperties() method. Then you should customize the ProvideValue() method to get the values of the appropriate RadDataFilter properties and pass them to the PersistenceManager. The RestoreValue() method, on the other hand, should determine how to use the persisted values to restore the saved state of the RadDataFilter.

    It is also important to note that the RadPersistenceFramework can save the persisted settings either in a file in the isolated storage or in a stream. This is why in your scenario, using the Save(object), Load(object,stream) methods is the better approach - you can use a StreamReader to read the contents of the stream and write the data in an xml file.

    I hope this information helps you better understand the RadPersistenceFramework logic. Please let us know if you have any additional questions or if you encounter any issues while implementing your scenario.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. sebastien
    sebastien avatar
    1 posts
    Member since:
    Apr 2014

    Posted 04 Mar Link to this post

    Hello,

    I've use this solution to save the filtor of my DataFilter but it doesn't work for custom filter ( not raise the rEditorCreatedEvent and the FilterOperatorsLoadingEvent).

    Is it possible to persist the custom filter? (the save is good and the filters are correctly load but can't be display).

    best regards,

    Sébastien

     

  6. Kiril Vandov
    Admin
    Kiril Vandov avatar
    324 posts

    Posted 09 Mar Link to this post

    Hello Sébastien,

    The RadPersistenceFramework should not have any problem saving and then loading any Properties as long as they have a public getters/setters in order to read and then write their values. As the entire save/load logic should be located in your CustomPropertyProvider I would like you to provide us with a sample project and steps reproducing the explained behavior. Doing so we will be able to better understand your scenario and provide you with the best possible answer based on your scenario. Please note that the RadPersistenceFramework cant persist events and event firing.

    Looking forward to hearing from you.

    Kind regards,
    Kiril Vandov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready