CurrentFilterFunction is changed to "EqualTo" when filter by CheckList

5 posts, 0 answers
  1. Adam Hughes
    Adam Hughes avatar
    8 posts
    Member since:
    Jan 2019

    Posted 19 Mar 2019 Link to this post

    I am filtering at server side.

    I am using FilterType="CheckList" for RadGrid and it works well (with default function "EqualTo").
    There is a textbox for each column, I can input some text and filter CurrentFilterFunction="Contains".

    Problem:
    After filtering by CheckList, it changes the CurrentFilterFunction to "EqualTo".
    So, I cannot filter with "Contains" function by textbox any more.

    Proposed Solution:
    There is any way to separate CurrentFilterFunction of CheckList filter and TextBox filter?

    Grid:

    <telerik:RadGrid Skin="Default" RenderMode="Lightweight" PageSize="20" runat="server" ID="RGridRisedueResultList" AllowPaging="true" AllowSorting="True" OnPreRender="RGridRisedueResultList_PreRender" OnFilterCheckListItemsRequested="RGridRisedueResultList_FilterCheckListItemsRequested" AutoGenerateColumns="False" FilterType="CheckList" AllowFilteringByColumn="True" OnNeedDataSource="RGridRisedueResultList_NeedDataSource">

     

    Column:
    <telerik:GridBoundColumn UniqueName="Lab" DataField="Lab" HeaderText="Lab" FilterCheckListEnableLoadOnDemand="true" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"> </telerik:GridBoundColumn>

     

  2. Adam Hughes
    Adam Hughes avatar
    8 posts
    Member since:
    Jan 2019

    Posted 19 Mar 2019 in reply to Adam Hughes Link to this post

    Filter by textbox is died until clear filter.
  3. Attila Antal
    Admin
    Attila Antal avatar
    623 posts

    Posted 22 Mar 2019 Link to this post

    Hi Adam,

    That is right, the Check List filter changes the FilterFunction to EqualTo, but you can change it back if it's no longer used. For example, as soon as clear filtering using the Check List, filter Function will get set back to Contains.

    You can do that in the ItemCommand Event. Using this event, you can apply a condition to check for a specific command, then another condition that will check whether the CheckList has any filter applied. If not, that means, the check list is not in use, and therefore, switch back the filter function to "Contains":

    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.FilterCommandName)
        {
            Pair args = e.CommandArgument as Pair;
     
            string filterFunction = args.First.ToString();
            string columnUniqueName = args.Second.ToString();
            GridColumn column = RadGrid1.MasterTableView.GetColumn(columnUniqueName);
     
            string[] filterValues = column.ListOfFilterValues;
     
            // if No filter is applied using the Filter CheckList
            if (filterValues == null || filterValues.Count() < 1)
            {
                // Change the Current Filter Function back to Contains
                column.CurrentFilterFunction = GridKnownFunction.Contains;
            }
        }
    }


    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.
  4. Adam Hughes
    Adam Hughes avatar
    8 posts
    Member since:
    Jan 2019

    Posted 24 Mar 2019 in reply to Attila Antal Link to this post

    Thank you, Attila for the quick response.
    Unfortunately, your suggestion does not solve my problem.

    I am filtering by CheckList and TextBox on the same column.
    Filtering by CheckBox is OK.
    But, after that, I type some text then press Enter, the filtering does not work because CurrentFilterFunction is "EqualTo".

    My idea to solve that problem:
    If the TextBox has something, clear the current filter value, set filter function to "Contains".

    Is there any config (no need code too much) to achieve that?

  5. Attila Antal
    Admin
    Attila Antal avatar
    623 posts

    Posted 27 Mar 2019 Link to this post

    Hi Adam,

    The required behavior is beyond the current built-in functionalities and changing this behavior requires custom code. The event handler and the example I have shared is the correct one for the behavior you want, but you will need to change the logic. Currently, the logic is checking, if there are no items checked in the CheckBoxList, then it changes the filter function back to Contains. If you revert that logic, or change the logic to check whether the Column has CurrentFilterValue, would then produce the exact behavior you are looking for.

    Please give it a try and let us know if you are facing difficulties.

    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