Kendo UI Grid Filtering column with multiple values

寵の児 提交于 2020-01-13 18:12:09

问题


I have been using filters to successfully search on my KendoUI grids. However a new application has some fields that are multi-valued and my filtering doesn't work - it actually just seems to spin forever.

An example of a multi-value field:

field   : "rspPersons",
title   : "Responsible Persons",
type    : "Text",
template: "# var t=rspPersons.join(', ');data.tagsString=t; # #=t #"

An example of my filter:

                        orfilter.filters.push( {
                            field : "chgDescription",
                            operator : "contains",
                            value : v1
                        },
                        orfilter.filters.push( {
                            field : "rspPersons",
                            operator : "contains",
                            value : v1
                        } 

The second filter will make the entire search break down. If I take it out, then the search/filter works just fine.

So how can I filter/search on multi-value fields?


回答1:


You'll need to push multiple filter criteria into filter array and assign it to the of Grid's datasource. Here's how I have done.

function onChange() {
    var filter = { logic: "or", filters: [] };
    //  values is an array containing values to be searched
    var values = this.value();
    $.each(values, function (i, v) {
        filter.filters.push({ field: "column_name", operator: "eq", value: v 
       });
    });
    var dataSource = $("#searchgrid").data("kendoGrid").dataSource;
    dataSource.filter(filter);
}



回答2:


You should set the logic option similar to the following.

                filter({
                        logic: "or",
                        filters: [{
                            field: "LastName",
                            operator: "contains",
                            value: value
                        },
                        {
                            field: "FirstName",
                            operator: "contains",
                            value: value
                        }]
                    })



回答3:


I create a seperate search textbox and then done the script like this it work's for me..

$("#search").keyup(function () {
        var selecteditem = $('#search').val();
        var kgrid = $("#gridName").data("kendoGrid");
        selecteditem = selecteditem.toUpperCase();
        var selectedArray = selecteditem.split(" ");
        if (selecteditem) {
            var orfilter = { logic: "or", filters: [] };
            var andfilter = { logic: "and", filters: [] };
            $.each(selectedArray, function (i, v) {
                if (v.trim() == "") {
                }
                else {
                    $.each(selectedArray, function (i, v1) {
                        if (v1.trim() == "") {
                        }
                        else {
                            orfilter.filters.push({ field: "GridColumnFields", operator: "contains", value: v1 },
                                                    { field: "LastName", operator: "contains", value: v1 },
                                                    { field: "FirstName", operator: "contains", value: v1 },
                                                     { field: "GridColumnFields", operator: "contains", value: v1 },

                                                    { field: "GridColumnFields", operator: "contains", value: v1 }
                                                    );
                            andfilter.filters.push(orfilter);
                            orfilter = { logic: "or", filters: [] };
                        }
                    });
                }
            });
            kgrid.dataSource.filter(andfilter);
        }
        else {
            kgrid.dataSource.filter({});
        }
    });

You can define the add columns that you needed in search filter

you can create the textbox for this in html

 <input type="text" id="search" name="search" />


来源:https://stackoverflow.com/questions/41987788/kendo-ui-grid-filtering-column-with-multiple-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!