How to apply filter with multiple columns

2 posts, 1 answers
  1. Cesar
    Cesar avatar
    3 posts
    Member since:
    Dec 2010

    Posted 30 Mar Link to this post

    I have a dropdownlist with multiple columns.

    When a user wants to filter something, i want to retrieve all the records which contains the filter text in any column, not only on text column.
    I have tried to manage the filter event, and change the filter, but its not working. What is it wrong with my code?

    01.@(Html.Kendo().DropDownList()
    02.                                        .Name("CEBE")
    03.                                        .HtmlAttributes(new { style = "width:100%" })
    04.                                        .OptionLabel("Seleccione...")
    05.                                        .HeaderTemplate("<div class=\"dropdown-header k-widget k-header\">" +
    06.                                            "<table><tr>" +
    07.                                            "<td style='width:110px'>CEBE</td>" +
    08.                                            "<td>Nombre</td>" +
    09.                                            "</tr></tabla>" +
    10.                                            "</div>")
    11.                                        .Template("<span class=\"k-state-default\"></span>" +
    12.                                            "<span class=\"k-state-default\">" +
    13.                                            "<table><tr>" +
    14.                                            "<td style='width:110px; padding-right:5px;'>#: data.Codigo#</td>" +
    15.                                            "<td style='width:auto;'>#: data.Nombre#</td>" +
    16.                                            "</tr></table>" +
    17.                                            "</span>")
    18.                                        .DataTextField("Nombre")
    19.                                        .DataValueField("Codigo")
    20.                                        .Filter(FilterType.Contains)
    21.                                        .Events(e=> e.Filtering("filterCebe"))
    22.                                        .BindTo((List<Sample.MaestrosService.CEBE>)ViewBag.ListaCebesUtilizados)
    23.                                    )
    24. 
    25.
    26.<script text="text/javascript">
    27.function filterCebe(e) {
    28.        debugger;
    29.        var filterValue = e.filter.value;
    30.        var newFilter = {
    31.            logic: "or",
    32.            filters: [
    33.                { field: "Nombre", operator: "contains", value: filterValue, ignoreCase: true },
    34.                { field: "Codigo", operator: "contains", value: filterValue, ignoreCase: true }
    35.            ]
    36.        };
    37.        var dll = $("#CEBE").data("kendoDropDownList");
    38.        dll.dataSource.filter(newFilter);
    39.    } </script>

     

     

  2. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 01 Apr Link to this post

    Hello Cesar,

     

    We've already replied to the ticket which you've opened. Please refrain from cross-posting.

     

    Here is the replay in the support thread:

     

    `

    This is not quite intended. However you could prevent the default filtering and then apply the new expression.

     

    I've created a quick example for this - http://dojo.telerik.com/@rusev/OQUrI. The important bits are in thefiltering event handler.

     

    `

     

    Regards,
    Nikolay Rusev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top