FilterExpression

10 posts, 0 answers
  1. Jon
    Jon avatar
    35 posts
    Member since:
    Sep 2013

    Posted 26 Jun 2014 Link to this post

    In the FilterExpression, I noticed Telerik is using ")||(" instead of ")OR(".  Evidently this works, but I believe the recommendation is "OR".  I only bring this up because in many situations, the RadGrid1.MasterTableView.FilterExpression can be used directly as the WHERE clause is in a SQL Query.  SQL understands "OR", but not "||".

    I'm using it for my where clause in my project to retrieve related data, so you might consider changing it just for me. :-)

    In the meantime RadGrid1.MasterTableView.FilterExpression.Replace("||", "OR") is working well.

    Thanks!
  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 01 Jul 2014 Link to this post

    Hello Jon,

    The FilterExpression for the RadGrid use "OR" and "AND" operators. If you would like, you could check the difference when using various data sources in this article. I am afraid that the "||" operator is not used.

    This said, would you elaborate more on the configuration that you have. What are the settings for the RadGrid? I would appreciate it if you could share your full markup with the code-behind so we could have better understanding of your scenario. Thank you in advance.


    Regards,
    Viktor Tachev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jon
    Jon avatar
    35 posts
    Member since:
    Sep 2013

    Posted 01 Jul 2014 in reply to Viktor Tachev Link to this post

    In the OnNeedDataSource, if you check the FilterExpression, it is using "||".  I replaced it with "OR" as in the following:
    var filter Expression = RadGrid1.MasterTableView.FilterExpression.Replace("||","OR");

    Is this not the code that creates the filter?
    public virtual string EvaluateFilterExpression(GridFilteringItem filteringItem)
    {
        if (!this.SupportsFiltering())
        {
            return string.Empty;
        }
     
        TableCell cell = filteringItem[this.UniqueName];
        string filterValue = this.GetCurrentFilterValueFromControl(cell);
     
        if (this.ListOfFilterValues != null && this.ListOfFilterValues.Length > 0)
        {
            if (this.CurrentFilterFunction == GridKnownFunction.EqualTo)
            {
                GridFilterFunction filterFunc = new GridFilterFunction(this.CurrentFilterFunction);
                StringBuilder exprBuilder = new StringBuilder();
                exprBuilder.Append("(");
                exprBuilder.Append(filterFunc.GetFunctionString(this.GetFilterDataField(), this.ListOfFilterValues[0], this.DataType, filteringItem.OwnerTableView));
                for (int i = 1; i < this.ListOfFilterValues.Length; i++)
                {
     
                    string filterPart = filterFunc.GetFunctionString(this.GetFilterDataField(), this.ListOfFilterValues[i], this.DataType, filteringItem.OwnerTableView);
                    if (!string.IsNullOrEmpty(filterPart))
                    {
                        exprBuilder.Append(")||(");
                        exprBuilder.Append(filterPart);
                    }
                }
                exprBuilder.Append(")");
                return exprBuilder.ToString();
            }
            else if (this.CurrentFilterFunction == GridKnownFunction.NoFilter)
            {
                this.ListOfFilterValues = null;
            }
        }
     
        if (String.IsNullOrEmpty(filterValue) && !FunctionTakesNoArguments(this.CurrentFilterFunction))
        {
            return "";
        }
        else
        {
            GridFilterFunction filterFunc = new GridFilterFunction(this.CurrentFilterFunction);
            //Get DataType of colum
            return filterFunc.GetFunctionString(this.GetFilterDataField(), filterValue, this.DataType, filteringItem.OwnerTableView);
        }
    }

    Maybe I'm misunderstanding something...
  5. Jon
    Jon avatar
    35 posts
    Member since:
    Sep 2013

    Posted 01 Jul 2014 in reply to Jon Link to this post

    To clarify, this is occurring when using a checkboxlist for a filter.
  6. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 04 Jul 2014 Link to this post

    Hi Jon,

    Thank you for the clarification.

    I am afraid that modifying the generated FilterExpression at this point would not be possible as it would introduce a breaking change.

    If you would like to use it directly to query a database you could use the approach that you currently have implemented - replacing the "||" string with "OR".

    Regards,
    Viktor Tachev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Jon
    Jon avatar
    35 posts
    Member since:
    Sep 2013

    Posted 07 Jul 2014 in reply to Viktor Tachev Link to this post

    Sounds good.  I don't blame you for not changing it.  I had noticed it and I saw on the page you referred to that it showed using an "OR", but it was using "||".  So, I thought I'd bring it up in case you wanted to change it, or the documentation, in the future.

    Thanks for your feedback.
  8. Vivek
    Vivek avatar
    4 posts
    Member since:
    Aug 2014

    Posted 12 Aug 2014 Link to this post

    I am having a similar problem. I need to set ListOfFilterValues = Nothing for a GridBoundColumn. My code is as follows:

    If TypeOf column Is GridBoundColumn Then
         Dim boundColumn As GridBoundColumn = TryCast(column, GridBoundColumn)
         boundColumn.FilterListOptions = GridFilterListOptions.AllowAllFilters
         DirectCast(column, Telerik.Web.UI.GridBoundColumn).ListOfFilterValues = Nothing

    End If

    However I am getting the error

    Error 1 'Telerik.Web.UI.GridColumn.Protected Friend Property ListOfFilterValues As String()' is not accessible in this context because it is 'Protected Friend'. 

    Any solution?

    Thanks
  9. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 14 Aug 2014 Link to this post

    Hi Vivek,

    If you would like to clear the filters that are applied in the RadGrid you could use an approach similar to the one below. It illustrates how you could clear the filters in the grid when a Button is clicked:

    Protected Sub clrFilters_Click(ByVal sender As Object, ByVal e As EventArgs)
        For Each column As GridColumn In RadGrid1.MasterTableView.Columns
            column.CurrentFilterFunction = GridKnownFunction.NoFilter
            column.CurrentFilterValue = String.Empty
        Next
        RadGrid1.MasterTableView.FilterExpression = String.Empty
        RadGrid1.MasterTableView.Rebind()
    End Sub


    Regards,
    Viktor Tachev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Vivek
    Vivek avatar
    4 posts
    Member since:
    Aug 2014

    Posted 14 Aug 2014 in reply to Viktor Tachev Link to this post

    Hi Viktor,

    Thanks for your reply. I tried your solution. It works
    partially. I have explained my problem in the attached document. Please let me
    know if you need any more clarification.

    Attachment failed. So I have emailed the attachment. 

    Thanks

     

    Vivek Arkalgud



  11. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 19 Aug 2014 Link to this post

    Hi Vivek,

    Would you send a formal support ticket and attach the files there? This would enable us to investigate the issue locally and look for its cause.

    Regards,
    Viktor Tachev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017