Filter problem when updated to Q2

6 posts, 1 answers
  1. Rabeeh
    Rabeeh  avatar
    62 posts
    Member since:
    Sep 2007

    Posted 13 Oct 2010 Link to this post

    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();
                }
            }
  2. Rabeeh
    Rabeeh  avatar
    62 posts
    Member since:
    Sep 2007

    Posted 13 Oct 2010 Link to this post


    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 
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 13 Oct 2010 Link to this post

    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
  5. Rabeeh
    Rabeeh  avatar
    62 posts
    Member since:
    Sep 2007

    Posted 13 Oct 2010 Link to this post

    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...

  6. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 13 Oct 2010 Link to this post

    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
  7. Rabeeh
    Rabeeh  avatar
    62 posts
    Member since:
    Sep 2007

    Posted 13 Oct 2010 Link to this post

    OK I will try it and confirm to you, thank you for the support
Back to Top
UI for WinForms is Visual Studio 2017 Ready