Apply filter expression on object programmatically

1 Answer 103 Views
DataFilter
Josef
Top achievements
Rank 1
Josef asked on 28 Oct 2021, 08:05 AM | edited on 28 Oct 2021, 09:15 AM
I'm wondering whether it is possible to apply a filter expression created by a Winforms RadFilterDialog on a specific object programmatically.
It should return a bool value depending the filter is true or false for the object and execute different code depending on the result.  The idea is to implement a simple rule engine.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Oct 2021, 01:29 PM

Hello, Josef,

RadDataFilter offers the Expression property which stores the defired filter expression in SQL-like format. Then, you can use this expression and apply it to a BindingSource for example and thus filter a control that uses this BindingSource as DataSource. The following help article demonstrates a sample approach how to filter the grid with the help of RadDataFilter: 

https://docs.telerik.com/devtools/winforms/controls/datafilter/getting-started 

However, for implementing simple rule engine, you can have a look at our RadValidationProvider: https://docs.telerik.com/devtools/winforms/controls/validation-provider/overview 

Since I am not familiar with the complete requirement that you are trying to achieve, I am not sure whether it would fit your scenario.

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

Regards,
Dess | Tech Support Engineer, Principal
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.

Josef
Top achievements
Rank 1
commented on 02 Nov 2021, 08:11 AM

Hello Dess, 

thanks for you explanations. 

That means for my intended purpose I'd have to program an extension like "bool object.FilterIsTrue(string filterExpression)"  and could then execute code depending on the result. 

My use-case simplified:
The user shall be able to create multiple rules/filters in a flexible way (maybe  using the RadFilterEditor)  and to define a key value pair if the filter is true for the a object. Finally a list of <Filter, Key, Value> would be exist and depending on the object an list of key-value pair can be generated, which can be used in the the further flow. 


Best regards, 
Josef

Dess | Tech Support Engineer, Principal
Telerik team
commented on 04 Nov 2021, 12:26 PM

Hello, Josef,

If I understand your requirement correctly, you need to have a method (or other appropriate API) that returns true/false indicating whether a specific custom object meets the passed expression or not. Then, considering the returned result, additional logic should be executed. Please correct me if I am wrong.
To be honest, I don't think that you need a UI control at all. This is custom logic that can be performed within a method that accepts the custom object and returns the boolean result. 

I have prepared a sample code snippet for better illustration: 
            foreach (NwindDataSet.ProductsRow productRow in this.nwindDataSet.Products)
            {
                if (IsPriceGreaterThan30(productRow))
                {
                    //TODO
                }
            }

        private bool IsPriceGreaterThan30(NwindDataSet.ProductsRow productRow)
        {
            if (productRow.UnitPrice>30)
            {
                return true;
            }
            return false;
        }
However, it is up to the developer to implement such kind of functionality.
Tags
DataFilter
Asked by
Josef
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or