使用多选剑道过滤数据源

莫替扎索

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

 $("#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 });
 }

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

伊桑·辛格

您必须使用多选的更改事件。您可以直接使用传递给数据源过滤器 API 的操作属性中的函数。

 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;
       }
 });

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章