【问题标题】:Kendo DropDownList Search on template modified textKendo DropDownList 搜索模板修改文本
【发布时间】:2017-01-06 22:49:18
【问题描述】:

我无法获得Kendo DropDownList 的内置搜索来使用模板化文本而不是来自数据源的原始文本。为了显示、值和搜索的目的,我想从数据源名称中去掉前导斜杠。

<script>
$("#dropdownlist").kendoDropDownList({
  dataSource: [ "/Apples", "/Oranges" ],

  // None of these templates appear to fix the search text.  
  // Kendo is using the dataSource item to search instead of the template output.
  // I want to be able to search using 'a' (for Apples) or 'o' (for Oranges).  
  // If I use '/' then it cycles through the items which proves to me that the search is not using templated text.

  template: function(t) { return t.name.slice(1); },
  valueTemplate: function(t) { return t.name.slice(1); },
  optionLabelTemplate : function (t) { return t.name.slice(1); },

});
</script>

这是 Kendo 的 UI 测试器中的一个不工作示例:

http://dojo.telerik.com/@Jeremy/UvOFo

我无法轻易更改服务器端的数据源。

如果无法更改搜索的工作方式,那么也许有办法在数据源从服务器加载到客户端后更改它?

【问题讨论】:

    标签: kendo-ui telerik kendo-dropdown


    【解决方案1】:

    我不确定这是否会对您有所帮助,但我能够强制它工作。该控件允许您订阅 init 上的过滤事件。从这里,您可以在提交之前设置过滤器的值。

    <script>
    $("#dropdownlist").kendoDropDownList({
        dataSource: ["/Apples", "/Oranges"],
        template: function(t) { return t.slice(1); },
        valueTemplate: function(t) { return t.slice(1); },
        optionLabelTemplate : function (t) { return t.slice(0); },
        filter: "startswith",
        filtering: function(e) {
            e.filter.value = '/'+e.filter.value;
        }
    });
    </script>
    

    【讨论】:

    • THX - 当我打开下拉菜单并在 filter 输入框中输入内容时,您的解决方案将起作用。我的问题不够清楚。 Kendo DropDownList 必须具有两种不同类型的过滤器/搜索功能。一个用于输入框,一个用于按键。我试图让按键搜索与集中但未打开的 DropDownList 一起使用。一旦定义了filter 属性,那么无论我输入“a”、“o”还是“/”,按键都不起作用。您的回答与问题大致相符,所以我会给您信用。我将切换我的 UI 以使用输入框而不是按键。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多