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

Filter problem when updated to Q2

5 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rabeeh
Top achievements
Rank 2
Rabeeh asked on 13 Oct 2010, 06:52 AM
I have a telerik grid and wrote a function to allow searching all the Grid text columns, by specifying the filter type and input, the function changes all the text columns filter expressions.

It used to work very well on Q1, in Q2 everything changed.

Function is the following, I need to know how to set filter expressions programmatically in the right way in Q2.

private void SetFilter(GridKnownFunction filterFnType, string searchInput)
        {
            FilterExpression filter;
            string input = searchInput.Trim();
        
            if (!string.IsNullOrEmpty(input))
            {
               
                foreach (GridViewDataColumn column in this._GridTextColumns)
                {
   
filter = new FilterExpression(FilterExpression.BinaryOperation.OR, filterFnType, "@FilterEditor1");
  
filter.Parameters.Add("@FilterEditor1", input);
 
  
 column.FilterDescriptor = filter;
                    
                }
            }
            else
            {
                this.grid_Data.MasterTemplate.FilterDescriptors.Clear();
            }
        }

5 Answers, 1 is accepted

Sort by
0
Rabeeh
Top achievements
Rank 2
answered on 13 Oct 2010, 08:24 AM

I followed tutorial here http://www.telerik.com/help/winforms/grid_setting-filters-programmatically.html

I noticed that the when I create the  FilterDescriptor programmtically


FilterDescriptor filter = new FilterDescriptor();
filter.PropertyName =
 "991A17E5-9842-40E9-983F-36D2CF07385E";
filter.Operator = FilterOperator.StartsWith;
filter.Value =
 "r";
filter.IsFilterEditor = true;

this.radGridView1.FilterDescriptors.Add(filter);


the expression becomes %r

but when I do filter from grid UI, the expression is %r% and it works 
0
Emanuel Varga
Top achievements
Rank 1
answered on 13 Oct 2010, 11:52 AM
Hello Rabeeh,

Sorry for the late response.
First I would like to say I'm glad you found your answer.
As for the filter expression is is working the same as the Like syntax for SQL, at leas as far as the % go.
For example, for strings, if:
- StartsWith: letter%,
- Contains: %letter%,
- EndsWith: %letter,
the default one for the grid is Contains, tha's why it is %lettter%.

Hope this clears up a few other things, but if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Rabeeh
Top achievements
Rank 2
answered on 13 Oct 2010, 12:17 PM
Thank for the reply,  and thanks for the tip, you are right.

It only worked from the UI.

It did not work programmatically through the function I wrote.

I want to filter Text columns programmatically from code.. This used to work in Q1 in Q2 it is not working...

0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 13 Oct 2010, 01:01 PM
Hello again,

Please take a look at this snippet:
FilterDescriptor filter = new FilterDescriptor();
filter.PropertyName = "Id";
filter.Operator = FilterOperator.Contains;
filter.Value = "5";
filter.IsFilterEditor = true;
radGridView1.FilterDescriptors.Add(filter);

This will give a filter expression of: Id LIKE '%5%' because the FilterOperator is set to Contains.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Rabeeh
Top achievements
Rank 2
answered on 13 Oct 2010, 01:16 PM
OK I will try it and confirm to you, thank you for the support
Tags
GridView
Asked by
Rabeeh
Top achievements
Rank 2
Answers by
Rabeeh
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
Share this question
or