隐藏非活动项目形成kendo Multiselect中的建议

时间:2017-09-29 20:52:50

标签: javascript kendo-ui kendo-asp.net-mvc kendo-multiselect

我的应用程序中有多选。我有一个要求,我们不应该在多选下拉建议列表中显示非活动用户。我们在模型中有旗帜。所以需要知道我们可以使用该标志过滤下拉列表。请找到附带的截图以获取想法。

我们可以使用该标志过滤ajax调用中的数据。但需要获取已选择的非活动用户的名称。所以我试图仅从建议列表中隐藏非活动用户。

因此需要显示所选的非活动用户,但需要隐藏非活动用户的建议。 enter image description here

1 个答案:

答案 0 :(得分:1)

不确定这是否是最佳方式,但您可以尝试在open事件中的dataSource上应用过滤器,并在close事件中将其删除:

$("#multiselect").kendoMultiSelect({
  dataSource: {
    data: [{Name: "test 1", Active: true, Id: 1},
          {Name: "test 2", Active: true, Id: 2},
          {Name: "test 3", Active: false, Id: 3},
          {Name: "test 4", Active: true, Id: 4},
          {Name: "test 5", Active: false, Id: 5}]
  },
  value: [1, 3],
  dataTextField: "Name",
  dataValueField: "Id",
  filter: "startswith",
  open: function(e) {
    this.dataSource.filter({ field: "Active", operator: "eq", value: "true" });
  },
  close: function() {
    this.dataSource.filter(null);
  }
});

Demo