This is a migrated thread and some comments may be shown as answers.

How to apply filter with multiple columns

1 Answer 754 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Cesar
Top achievements
Rank 1
Cesar asked on 30 Mar 2016, 07:42 AM

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>

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 01 Apr 2016, 02:16 PM

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!
 
Tags
DropDownList
Asked by
Cesar
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or