Multiple expression filtering in radgrid

9 posts, 0 answers
  1. Calin
    Calin avatar
    12 posts
    Member since:
    Feb 2019

    Posted 19 Jun Link to this post

    I have a radgrid I am using to hold data about client interests likes and dislikes. I need the user to be able to filter the results. I was using radfilter, and it works, but is very complicated for the end user and is too confusing. I thought that the way it is set up in the rad grid itself may be easier. 

    Though from what I can tell, I can only do one expression at a time. I cannot do "and" and "or" expressions. Say I wanted to see who likes TV-Cartoon and who likes TV-Outdoors. Is there a way I can make BOTH of those appear? 

    As far as I can tell, you can only type one thing in the text box, use the filter drop down (I just used contains) and have that one expression show. Is there a way to do multiple?

  2. Attila Antal
    Admin
    Attila Antal avatar
    427 posts

    Posted 24 Jun Link to this post

    Hi Calin,

    The Excel-Like filtering functionality of the grid has the option to filter using multiple values (e.g. Value1 AND Value2). Please check out the Grid - Excel-like Filtering demo to see it in action.

    Additionally you can check out the following articles that could be helpful to achieve the described behavior::
    Kind regards,
    Attila Antal
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Calin
    Calin avatar
    12 posts
    Member since:
    Feb 2019

    Posted 24 Jun in reply to Attila Antal Link to this post

    Attila, yes, I saw the excel like filtering, and I see that I can do Value1 AND Value2... but I do not see an OR option, which the clients using the application need. I will look into the other things, but it is necessary to be able to do AND and OR filtering as that is what they have requested. 
  4. Attila Antal
    Admin
    Attila Antal avatar
    427 posts

    Posted 24 Jun Link to this post

    Hi Calin,

    I apologize, I have missed out one of the most important articles. That is the Header Context Menu. By getting familiar with the article, you will be able to change the HeaderContextMenu options and add/change/remove items as necessary.

    Then you can use the custom filtering options/items in combination with the FilterCommand described in the Custom Filter Options with Handling you can apply any kind of filtering.
    Kind regards,
    Attila Antal
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.

  5. Calin
    Calin avatar
    12 posts
    Member since:
    Feb 2019

    Posted 24 Jun in reply to Attila Antal Link to this post

    Thank you Attila. I will continue diving into this. The other option, was to use the RadFilter to filter the RadGrid, but seeing as how its just a bunch of buttons, this is confusing for those using the application. That does have the OR option I need though, by default. Are there any ways that RadFilter could be made more user friendly, without typing out a document they have to read every time they want to use it? We thought about hiding the control itself, using "prebuilt" functions that would be popular, and a button to click that would put all that information into the RadFilter and do it for them. Is this possible? Something like the picture attached. 
  6. Attila Antal
    Admin
    Attila Antal avatar
    427 posts

    Posted 27 Jun Link to this post

    Hi Calin,

    Manipulating the FilterExpressions described in the Operate filter expressions article I've shared earlier may be an simpler approach. RadFilter does not even have to be used.

    Create the Controls that will be used for filtering (similar to those from the picture you have shared)

    <telerik:RadLabel ID="RadLabel1" runat="server" AssociatedControlID="RadTextBox1" Text="ShipName Contains"></telerik:RadLabel>
    <telerik:RadTextBox ID="RadTextBox1" runat="server" Text="3"></telerik:RadTextBox>
    <telerik:RadLabel ID="RadLabel2" runat="server" AssociatedControlID="RadTextBox2" Text="OR"></telerik:RadLabel>
    <telerik:RadTextBox ID="RadTextBox2" runat="server" Text="4"></telerik:RadTextBox>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Filter" OnClick="RadButton1_Click"></telerik:RadButton>
    <br />
    <br />
    <telerik:RadLabel ID="RadLabel3" runat="server" AssociatedControlID="RadTextBox3" Text="ShipName Contains"></telerik:RadLabel>
    <telerik:RadTextBox ID="RadTextBox3" runat="server" Text="1"></telerik:RadTextBox>
    <telerik:RadLabel ID="RadLabel4" runat="server" AssociatedControlID="RadTextBox4" Text="AND"></telerik:RadLabel>
    <telerik:RadTextBox ID="RadTextBox4" runat="server" Text="6"></telerik:RadTextBox>
    <telerik:RadButton ID="RadButton2" runat="server" Text="Filter" OnClick="RadButton2_Click"></telerik:RadButton>
    <br />
    <br />
    <telerik:RadButton ID="RadButton3" runat="server" Text="Clear" OnClick="RadButton3_Click"></telerik:RadButton>


    Create the Grid and set the AllowFilteringByColumn property to true to enable the filtering, and IsFilterItemExpanded property to false, to hide the Filter row.

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="true">
        <MasterTableView  IsFilterItemExpanded="false">
        </MasterTableView>
    </telerik:RadGrid>

    When clicking the Filter button of each filtering criteria:

    Filter using Value1 "OR" Value2

    protected void RadButton1_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(RadTextBox1.Text) || string.IsNullOrEmpty(RadTextBox2.Text)) return;
     
        StringBuilder filterExpression = new StringBuilder();
        filterExpression.Append(string.Format("(it[\"ShipName\"].ToString().Contains(\"{0}\") OR it[\"ShipName\"].ToString().Contains(\"{1}\"))", RadTextBox1.Text, RadTextBox2.Text));
        RadGrid1.MasterTableView.FilterExpression = filterExpression.ToString();
        RadGrid1.Rebind();
    }

    Filter using Value1 "AND" Value2

    protected void RadButton2_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(RadTextBox3.Text) || string.IsNullOrEmpty(RadTextBox4.Text)) return;
     
        StringBuilder filterExpression = new StringBuilder();
        filterExpression.Append(string.Format("(it[\"ShipName\"].ToString().Contains(\"{0}\") AND it[\"ShipName\"].ToString().Contains(\"{1}\"))", RadTextBox3.Text, RadTextBox4.Text));
        RadGrid1.MasterTableView.FilterExpression = filterExpression.ToString();
        RadGrid1.Rebind();
    }

    Clear the Filter:

    protected void RadButton3_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(RadGrid1.MasterTableView.FilterExpression)) RadGrid1.MasterTableView.FilterExpression = string.Empty;
        RadGrid1.Rebind();
    }

    Attached you can find a WebForms page demonstrating this scenario. Please download and test sample to see if that is what you are looking for. The code is fully runnable, you can either import the page into a Web Site project or copy its source code.

    Kind regards,
    Attila Antal
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Calin
    Calin avatar
    12 posts
    Member since:
    Feb 2019

    Posted 27 Jun in reply to Attila Antal Link to this post

    Thank you, I will take a look at this, and see if I can do this in VB instead of C#.
  8. Calin
    Calin avatar
    12 posts
    Member since:
    Feb 2019

    Posted 27 Jun in reply to Attila Antal Link to this post

    I also should have been more specific. I do not want the same thing every time in the text boxes. Just the same set up, and filtering per line. 

     

    So one should be able to do:

    individual likes __________(text box) OR  ____________(text box)      (button here)

     

    and put whatever they need in each box. One time, it could be likes cats OR dogs. Another time, parrots OR pigs. The text boxes will change depending on what exactly they want to filter; the filtering itself (this or that) should stay prebuilt and the same. The possibility of interests will be a couple hundred long possibly. There is no way to guarantee that cats OR dogs would be a popular search every time the web form is loaded. But needing to filter by "anything" or "anything" is. 

  9. Attila Antal
    Admin
    Attila Antal avatar
    427 posts

    Posted 27 Jun Link to this post

    Hi Calin,

    I apologize, I was not aware of your preferred coding language. 

    Below I will share the VB version of the code:

    Protected Sub RadButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
        If String.IsNullOrEmpty(RadTextBox1.Text) OrElse String.IsNullOrEmpty(RadTextBox2.Text) Then Return
        Dim filterExpression As StringBuilder = New StringBuilder()
        filterExpression.Append(String.Format("(it[""ShipName""].ToString().Contains(""{0}"") OR it[""ShipName""].ToString().Contains(""{1}""))", RadTextBox1.Text, RadTextBox2.Text))
        RadGrid1.MasterTableView.FilterExpression = filterExpression.ToString()
        RadGrid1.Rebind()
    End Sub
     
     
    Protected Sub RadButton2_Click(ByVal sender As Object, ByVal e As EventArgs)
        If String.IsNullOrEmpty(RadTextBox3.Text) OrElse String.IsNullOrEmpty(RadTextBox4.Text) Then Return
        Dim filterExpression As StringBuilder = New StringBuilder()
        filterExpression.Append(String.Format("(it[""ShipName""].ToString().Contains(""{0}"") AND it[""ShipName""].ToString().Contains(""{1}""))", RadTextBox3.Text, RadTextBox4.Text))
        RadGrid1.MasterTableView.FilterExpression = filterExpression.ToString()
        RadGrid1.Rebind()
    End Sub
     
     
    Protected Sub RadButton3_Click(ByVal sender As Object, ByVal e As EventArgs)
        If Not String.IsNullOrEmpty(RadGrid1.MasterTableView.FilterExpression) Then RadGrid1.MasterTableView.FilterExpression = String.Empty
        RadGrid1.Rebind()
    End Sub

    The text for each textbox was pre-populated for testing purposes. You can remove them easily by removing the Text properties of each TextBox control.

    Kind regards,
    Attila Antal
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top