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

SQL to FilterDescriptor?

6 Answers 215 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pioter
Top achievements
Rank 1
Pioter asked on 17 Mar 2021, 03:30 PM

Hi,

When I query a RadGridView column's FilterDescriptor (.ToString()) I am getting basically an SQL representation of the applied filter, for example:

([coupon] >= 0.5) AND (([analytics_model_class] LIKE '%Other%' OR [analytics_model_class] NOT LIKE '%Card%'))

However, when I have to set the FilterDescriptor programmatically, I need to use the code as described here:

https://docs.telerik.com/devtools/winforms/controls/gridview/filtering/setting-filters-programmatically-(composite-descriptors)

This is pretty hard if I load a previously created SQL-like clause and now need to parse it in order to set the FilterDescriptors for all the columns.

Seems to me that there should be a utility available for this kind of purpose already, especially since Telerik already converts FilterDescriptors to SQL-like clauses.

Is there something that can help?

Thank you

Peter

 

 

 

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Mar 2021, 11:40 AM
Hello, Peter, 

RadGridView manages the filtering operation in its columns by using FilterDescriptors. Every FilterDescriptor and the whole FilterDescriptors collection has Expression property which converts the stored filtering data to a string expression by using the FilterDescriptor.GetExpression(descriptor, this.FormatDescriptorValue) property (where this is the FilterDescriptor instance). 

The reversed conversion is available by setting the column's Expression property or the FilterDescriptors.Expression property. 
  this.radGridView1.FilterDescriptors.Expression = @"[ProductName] LIKE '%w%' AND [ProductID] > 2";

As a result, the RadGridView.FilterDescriptors collection will be populated and the grid data will be filtered. If you want to load the data parsed form the expression to the filter row, you can use the following code snippet: 

            foreach (FilterDescriptor fd in this.radGridView1.FilterDescriptors)
            {
                fd.IsFilterEditor = true;
            }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Pioter
Top achievements
Rank 1
answered on 18 Mar 2021, 03:24 PM

Thank you, this almost works, however, here is the problem. The now filtered grid does not visually appear filtered - that is the filter indicators in the column headers don't show that a filter is present - and you cannot get the column's filter from the column's FilterDescriptor. This means that the application of the filter in the way you suggest does not restore the grid to the state that is functionally and visually identical to the one that would be achieved by manual application of the filters.

I know that setting individual columns' FilterDesriptors would have worked - the grid  would appear visually fitered - but unfortunately the individual columns FilterDescriptor.Expression property is not settable!

Do you have any suggestions?

 

0
Pioter
Top achievements
Rank 1
answered on 18 Mar 2021, 03:32 PM
Apologies! My previous reply is totally wrong as I did not understand the idea behind the second part of your answer. I see now that it does the trick!  Thank you very much!
0
Pioter
Top achievements
Rank 1
answered on 26 Mar 2021, 05:28 PM

After using this code for a few days I realized that something strange is still going on. So, indeed the filtering works as described above. However! the filter indicator in the column does not appear right away. Instead, it appears only when I horizontally scroll in the grid!

The two screenshots demonstrate this - the yellow indicator is only there after I scrolled to the right my grid. 

To be clear - the filter itself got applied and is working - only the fact that the indicator is not yellow is the problem

Can you suggest a fix?

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Mar 2021, 12:05 PM
Hello, Pioter, 

If the FilterDescriptor.IsFilterEditor property is set to true and you still doesn't have any indication for applied filters in the filter buttons, I can suggest you to refresh the grid:
        private void radButton1_Click(object sender, EventArgs e)
        {
             this.radGridView1.FilterDescriptors.Expression = @"[ProductName] LIKE '%w%' AND [ProductID] > 2";

            foreach (FilterDescriptor fd in this.radGridView1.FilterDescriptors)
            {
                fd.IsFilterEditor = true;
            }
            this.radGridView1.MasterTemplate.Refresh();
        }

This is expected to do the trick. Please give it a try and see how it works on your end.

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Pioter
Top achievements
Rank 1
answered on 05 Apr 2021, 09:34 PM
Dess, thank you very much, your suggestion worked!
Tags
General Discussions
Asked by
Pioter
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Pioter
Top achievements
Rank 1
Share this question
or