Kendo ui 剑道网格自定义过滤器以编程方式设置过滤器值

Kendo ui 剑道网格自定义过滤器以编程方式设置过滤器值,kendo-ui,telerik,kendo-grid,kendo-combobox,Kendo Ui,Telerik,Kendo Grid,Kendo Combobox,我试图以编程方式设置剑道网格自定义过滤器的过滤器值。我正在应用新的筛选值,如: gridOptions.dataSource.filter = [ { field: 'MyField', operator: 'eq', value: newTextValue } ]; 网格选项中的字段定义如下所示: { width: '140px', title: 'MyFieldTitle', field: 'MyField'

我试图以编程方式设置剑道网格自定义过滤器的过滤器值。我正在应用新的筛选值,如:

gridOptions.dataSource.filter = [
    {
      field: 'MyField',
      operator: 'eq',
      value: newTextValue
    }
];
网格选项中的字段定义如下所示:

{
     width: '140px',
     title: 'MyFieldTitle',
     field: 'MyField',
     filterable: getFieldFilter()
}
使用以下过滤器:

function getFieldFilter() {
  return {
    cell: {
      template: function (args) {
        var element = args.element;

        element.kendoComboBox({
          dataSource: {
            transport: {
              read: 'api/Items'
            }
          },
          valuePrimitive: true,
          dataTextField: 'Description',
          dataValueField: 'Code'
        });
      },
      showOperators: false
    }
  };
}
如果如上图所示应用过滤器,则只有在单击列中的kendoComboBox并再次单击其外部后,它才会起作用。 我最初的想法是剑道网格不会应用
dataValueField
,而只是设置
dataTextField
。当我检查kendo网格发送到服务器的请求时,我看到它发送到kendoComboBox本身中存储的值(文本),而不是后面的值

如果我从UI的kendoComboBox中选择了一些东西,那么一切都正常。但如果我像上面那样以编程方式设置它,它就不会

我是否需要刷新某种状态以使kendoComboBox刷新其内部值,或者如何解决此问题

编辑: 我想做的是从网格中获取
kendoCombobox
的值

var currentlyAppliedFilters = grid.dataSource.filter().filters;
for (var filter of currentlyAppliedFilters) {
    if (filter.field === 'MyField') {
      var currentlyApplied = filter.value;
    }
}

因此,上面的代码将为我提供
kendoCombobox
中项目的
Description
属性,但我实际想要得到的是
code
属性。

最初,当数据源没有筛选器时,单元格筛选器需要一个选项标签。这样第一个值就不会显示为选中

例如:

如果需要在绑定时过滤网格,则应向数据源添加默认过滤器

例如:


希望这能有所帮助。

在我的例子中,它似乎有所不同,要么是因为我使用了不同的
dataTextField
dataValueField
,要么是因为我有一个带有文本输入的
kendoDropDownList
 args.element.kendoDropDownList({
                                dataSource: args.dataSource,
                                optionLabel: "Select a color...",
                                dataTextField: "color",
                                dataValueField: "color",
                                valuePrimitive: true
                            });
 dataSource: { 
          data:[ { color: "#ff0000", size: 30 }, { color: "#000000", size: 33 }] ,
          filter: { field: "color", operator: "eq", value: "#ff0000" }
                    }