Kendo ui 使用多选剑道筛选数据源

Kendo ui 使用多选剑道筛选数据源,kendo-ui,Kendo Ui,我有一个网格和一个multiselect,我想根据我选择的内容通过multiselect过滤网格,当我取消选择时,网格应该相应地过滤,这是我的网格: $("#grid").kendoGrid({ dataSource: ds2, height: 550, sortable: true,

我有一个网格和一个multiselect,我想根据我选择的内容通过multiselect过滤网格,当我取消选择时,网格应该相应地过滤,这是我的网格:

 $("#grid").kendoGrid({                   
                dataSource: ds2,                   
                height: 550,                  
                sortable: true,
                pageable: {
                    refresh: true,
                    pageSizes: true,
                    buttonCount: 5
                },          
                  columns: [
                       { field: "name",
                         title: "Name",width:"50px"},
                       { field: "Description",
                       title: "Description", width: "80px"
                       },
                       { field: "WindSpeed",
                       title: "Wind Speed", width: "40px"
                       },
                       { field: "RPM",
                       title: "RPM", width: "40px"
                       },
                       { field: "Power",
                       title: "Power", width: "40px"
                       }
                      ]
            });
绑定数据源的数据:

 var ds1 = new kendo.data.DataSource({
                data: rsturn_f.EventNames
            });

   var ds2 = new kendo.data.DataSource({
                data: rsturn_f.Data
            });
以下是多选:

 $("#evnts").kendoMultiSelect({
                placeholder: "Select products...",
                dataTextField: "Nme",
                dataValueField: "Nme",
                //autoBind: false,
                select: onSelect,
                deselect: onDeselect,
                dataSource: ds1

            });
通过onselect,我可以这样做:

 function onSelect(e) {

                ds2.filter({ field: "Description", operator: "startswith", value: e.dataItem });
 }

现在,如果我想对多个值进行筛选并通过从multiselect中删除值来取消筛选,我不知道该怎么办,知道吗?

您必须使用multiselect的更改事件。您可以直接使用传递给dataSource filter API的operation属性中的函数

 function onChange(e) {
     ds2.filter({ field: "Description", value: this.value(), 
          operator: function(currentValue, filterValues){
               if(filterValues.length===0){
                  return true;
               }

                   if(filterValues.indexOf(currentValue)!==-1){
                      return true;
                   } 

               return false;
       }
 });

}

我删除了for循环。我已经做了一个演示