This is a migrated thread and some comments may be shown as answers.

Store filterdescriptors in database

9 Answers 190 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jan
Top achievements
Rank 1
Jan asked on 18 Jan 2017, 10:59 AM

Hello,

I'm looking for the best approach to store a radgridviews filterdescriptors in a db, so that the users could for instance use a dropdown menu to select and save their favourite filter settings. I'm already using the save/load layout funktionality which works great but I would prefer a way to only store the filters.
Any pointers and suggestions is greatly appretiated.
Thanks
Jan

9 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Jan 2017, 01:55 PM
Hello Jan,

Thank you for writing.

The grid supports this out of the box and stores layout information as well. Detailed information is available here:  Save and Load Layout | RadGridView.

I hope this information is useful. Let me know if you need further assistance.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jan
Top achievements
Rank 1
answered on 19 Jan 2017, 07:43 AM

Hello,

Thank you for your quick reply.

I'm already using the Save and Load Layout functionality, letting the users save and apply their layout.
However I'm looking for a way to store filters only without having to store the entire layout, so that the users can apply their layout (visible columns, column orders, with etc) and then apply a favourite filter regardless of the selected layout.
I have looked at this http://docs.telerik.com/devtools/winforms/gridview/save-and-load-layout/advanced but haven't been able to understand how to store the filters only and then apply them without making any changes to the other properties of the grid.

I hope this is a better explanation of my scenario.

Kind regards

Jan

0
Dimitar
Telerik team
answered on 19 Jan 2017, 11:22 AM
Hello Jan,

Here is how you can save the filters and layout separately:
private void radButton1_Click(object sender, EventArgs e)
{
    radGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = true;
    radGridView1.XmlSerializationInfo.SerializationMetadata.Clear();
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(RadGridView), "MasterTemplate", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Operator", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Value", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "IsFilterEditor", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.SaveLayout("Filters.xml");
 
}
 
private void radButton2_Click(object sender, EventArgs e)
{
    radGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = true;
    radGridView1.XmlSerializationInfo.SerializationMetadata.Clear();
 
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(RadGridView), "MasterTemplate", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Columns", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Name", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Width", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "FieldName", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "HeaderText", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.SaveLayout("Layout.xml");
 
}

I hope this will be useful.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jan
Top achievements
Rank 1
answered on 20 Jan 2017, 07:31 AM

Hello Dimitar!

Thank you this is what I was looking for!
One more question though. I dont't get it to work when using composite filters.
I get this:

<RadGridView>
  <MasterTemplate>
    <FilterDescriptors>
      <Telerik.WinControls.Data.CompositeFilterDescriptor PropertyName="fldBR" Operator="Contains" Value="" IsFilterEditor="True" />
      <Telerik.WinControls.Data.CompositeFilterDescriptor PropertyName="fldOrt" Operator="Contains" Value="" IsFilterEditor="True" />
    </FilterDescriptors>
  </MasterTemplate>
</RadGridView>

 

And this is the desired/expected output:

<RadGridView>
  <MasterTemplate>
    <FilterDescriptors>
      <Telerik.WinControls.Data.CompositeFilterDescriptor NotOperator="False" PropertyName="fldBR" Operator="Contains" Value="" IsFilterEditor="True">
        <FilterDescriptors>
          <Telerik.WinControls.Data.FilterDescriptor PropertyName="fldBR" Operator="IsNotEqualTo" Value="62" IsFilterEditor="False" />
          <Telerik.WinControls.Data.FilterDescriptor PropertyName="fldBR" Operator="IsNotEqualTo" Value="8" IsFilterEditor="False" />
        </FilterDescriptors>
      </Telerik.WinControls.Data.CompositeFilterDescriptor>
      <Telerik.WinControls.Data.CompositeFilterDescriptor NotOperator="False" PropertyName="fldOrt" Operator="Contains" Value="" IsFilterEditor="True">
        <FilterDescriptors>
          <Telerik.WinControls.Data.FilterDescriptor PropertyName="fldOrt" Operator="IsNotEqualTo" Value="London" IsFilterEditor="False" />
        </FilterDescriptors>
      </Telerik.WinControls.Data.CompositeFilterDescriptor>
    </FilterDescriptors>
  </MasterTemplate>
</RadGridView>

 

Thank you!

Kind regards

Jan

0
Dimitar
Telerik team
answered on 20 Jan 2017, 12:12 PM
Hi Jan,

Thank you for writing.

You should initialise the serialization metadata like this:
private void radButton1_Click(object sender, EventArgs e)
{
    radGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = true;
    radGridView1.XmlSerializationInfo.SerializationMetadata.Clear();
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(RadGridView), "MasterTemplate", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(CompositeFilterDescriptor), "FilterDescriptors", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(CompositeFilterDescriptor), "LogicalOperator", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "PropertyName", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Operator", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "Value", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(FilterDescriptor), "IsFilterEditor", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.SaveLayout("Filters.xml");
 
}

Please do not hesitate to contact us with any additional questions or concerns. 

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jan
Top achievements
Rank 1
answered on 20 Jan 2017, 12:49 PM

Thank you Dimitar,

This is working like a charm!
Is there also any simple way to clear the filter settings that has been applied using XmlSerializationInfo?
I've tried this.radGridView1.MasterTemplate.FilterDescriptors.Clear(); but it doesn't seem to fully reset all the options when using the "excel style" filters.

Thanks for your patience.

Kind regards

Jan

0
Jan
Top achievements
Rank 1
answered on 20 Jan 2017, 01:01 PM

Hello again,

Solved it byt calling this.radGridView1.LoadLayout(emptylayout.xml);
And in emptylayout.xml it just says: <RadGridView />

Thank you

Jan

 

0
Dimitar
Telerik team
answered on 23 Jan 2017, 09:44 AM
Hello Jan,

Both approaches are correct and working on my side.

If you want us to further investigate the case with the excel like filters please open a new thread and describe the exact case where the filters are not cleared. 

Please do not hesitate to contact us with any additional questions or concerns. 
 
Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jeffrey
Top achievements
Rank 1
Veteran
Iron
Iron
answered on 19 Oct 2022, 03:55 AM

Hello

Telerik Admin: please update the https://docs.telerik.com/devtools/winforms/controls/gridview/save-and-load-layout/advanced article to include Excel Like Filtering Composite Descriptors. 

Thank you

Dess | Tech Support Engineer, Principal
Telerik team
commented on 20 Oct 2022, 09:47 AM

Thank you, Jeffrey, for the provided feedback. We will review the referred article and update it accordingly in order to be as useful as possible.
Tags
GridView
Asked by
Jan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Jan
Top achievements
Rank 1
Jeffrey
Top achievements
Rank 1
Veteran
Iron
Iron
Share this question
or