RadGridView Filter Settings

8 posts, 0 answers
  1. John Thompson
    John Thompson avatar
    44 posts
    Member since:
    Dec 2009

    Posted 05 Oct 2010 Link to this post

    In the 0924 release of the Silverlight 4 controls I get the following in my serialization of the filter settings:

    System.Runtime.Serialization.InvalidDataContractException: Type 'Telerik.Windows.Data.FilterDescriptor+FilterDescriptorUnsetValue' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.

    The setting are created from your example code and then serialized for saving in the database.  The serialization code looks like this:

    List<Type> types = new List<Type>();
     
    types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.ColumnSetting>));
    types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.FilterSetting>));
    types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.GroupSetting>));
    types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.SortSetting>));
    types.Add(typeof(List<Telerik.Windows.Controls.GridView.Settings.PropertySetting>));
     
    DataContractSerializer serializer = new DataContractSerializer(settings.Settings.GetType(), types);
     
    MemoryStream ms = new MemoryStream();
     
    serializer.WriteObject(ms, settings.Settings);

    What do I need to change to restore functionality for my users?

  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 06 Oct 2010 Link to this post

    Hello John Thompson,

    You have to modify your code a little bit.

    In the place where the filters are serialized add the following check. If the a FilterDescriptor.Value == FilterDescriptor.UnsetValue then do not serialize this filter and continue. For example:

    if (!(cfd.FieldFilter.Filter1.Value == FilterDescriptor.UnsetValue))
    {
        setting.Filter1 = new Telerik.Windows.Data.FilterDescriptor();
        setting.Filter1.Member = cfd.FieldFilter.Filter1.Member;
        setting.Filter1.Operator = cfd.FieldFilter.Filter1.Operator;
        setting.Filter1.Value = cfd.FieldFilter.Filter1.Value;
        setting.Filter1.MemberType = null;
    }
     
    if (!(cfd.FieldFilter.Filter2.Value == FilterDescriptor.UnsetValue))
    {
        setting.Filter2 = new Telerik.Windows.Data.FilterDescriptor();
        setting.Filter2.Member = cfd.FieldFilter.Filter2.Member;
        setting.Filter2.Operator = cfd.FieldFilter.Filter2.Operator;
        setting.Filter2.Value = cfd.FieldFilter.Filter2.Value;
        setting.Filter2.MemberType = null;
    }
     
    foreach (Telerik.Windows.Data.FilterDescriptor fd in cfd.DistinctFilter.FilterDescriptors.OfType<Telerik.Windows.Data.FilterDescriptor>())
    {
        if (fd.Value == FilterDescriptor.UnsetValue)
        {
            continue;
        }
        Telerik.Windows.Data.FilterDescriptor newFd = new Telerik.Windows.Data.FilterDescriptor();
        newFd.Member = fd.Member;
        newFd.Operator = fd.Operator;
        newFd.Value = fd.Value;
        newFd.MemberType = null;
        setting.SelectedDistinctValues.Add(newFd);
    }

    Conversely, add a check for null on the way back when you deserialize. For example:

    if (setting.Filter1 != null)
    {
        cfd.FieldFilter.Filter1.Member = setting.Filter1.Member;
        cfd.FieldFilter.Filter1.Operator = setting.Filter1.Operator;
        cfd.FieldFilter.Filter1.Value = setting.Filter1.Value;
    }
     
    if (setting.Filter2 != null)
    {
        cfd.FieldFilter.Filter2.Member = setting.Filter2.Member;
        cfd.FieldFilter.Filter2.Operator = setting.Filter2.Operator;
        cfd.FieldFilter.Filter2.Value = setting.Filter2.Value;
    }
     
    foreach (Telerik.Windows.Data.FilterDescriptor descriptor in setting.SelectedDistinctValues)
    {
        cfd.DistinctFilter.FilterDescriptors.Add(descriptor);
    }

    You get the idea -- if there is a filter with this UnsetValue as its Value -- simply ignore it altogether.

    I hope this helps.

    Sincerely yours,
    Ross
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. John Thompson
    John Thompson avatar
    44 posts
    Member since:
    Dec 2009

    Posted 06 Oct 2010 Link to this post

    Your hopes are realized.  It worked great!  I also added a check as follows to allow the user to load pre-0924 filters.

    if (setting.Filter1 != null)
    {
        cfd.FieldFilter.Filter1.Member = setting.Filter1.Member;
        cfd.FieldFilter.Filter1.Operator = setting.Filter1.Operator;
     
        if (setting.Filter1.Value != null)
        {
            cfd.FieldFilter.Filter1.Value = setting.Filter1.Value;
        }
        else
        {
            cfd.FieldFilter.Filter1.Value = Telerik.Windows.Data.FilterDescriptor.UnsetValue;
        }
    }
     
    if (setting.Filter2 != null)
    {
        cfd.FieldFilter.Filter2.Member = setting.Filter2.Member;
        cfd.FieldFilter.Filter2.Operator = setting.Filter2.Operator;
     
        if (setting.Filter2.Value != null)
        {
            cfd.FieldFilter.Filter2.Value = setting.Filter2.Value;
        }
        else
        {
            cfd.FieldFilter.Filter2.Value = Telerik.Windows.Data.FilterDescriptor.UnsetValue;
        }
    }

    It seems to be working like a charm!  Thank you so much for your help.
  5. Prince
    Prince avatar
    2 posts
    Member since:
    Jun 2012

    Posted 13 Feb 2012 Link to this post

    Im working on radgridview to save settings to the database and return wen user select saved settings, In the forum  i can find where you do that, any help
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Feb 2012 Link to this post

    Hello,

     You could check this forum thread for more information on that topic.

    All the best,
    Didie
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  7. Mask
    Mask avatar
    20 posts
    Member since:
    Sep 2009
  8. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 15 Feb 2012 Link to this post

    Hello,

    In what way is your question related with the topic that we discuss in this thread?

    Please, don't spam a Save/Load Filter Settings topic with something that is totally unrelated.

    You can open a new forum thread if you want to (it is free), not just post your question if the very first forum thread that you see even though it has absolutely nothing to do with it.

    Does this make any sense?

    Greetings,
    Ross
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  9. Mask
    Mask avatar
    20 posts
    Member since:
    Sep 2009

    Posted 15 Feb 2012 Link to this post

    Could you answer it?
Back to Top
DevCraft banner