【发布时间】:2014-04-09 22:59:19
【问题描述】:
我正在使用 Kendo UI DropDownList,但找不到对其中的值进行分组的方法。有这个功能吗?
从 2013 年初看到以下帖子,其中说这是在路线图上,但不确定它是否已实施。
http://www.telerik.com/forums/option-group-for-datasource-in-dropdownlist
【问题讨论】:
我正在使用 Kendo UI DropDownList,但找不到对其中的值进行分组的方法。有这个功能吗?
从 2013 年初看到以下帖子,其中说这是在路线图上,但不确定它是否已实施。
http://www.telerik.com/forums/option-group-for-datasource-in-dropdownlist
【问题讨论】:
从 2015 年第一季度版本开始,数据源支持此功能。不过,在绑定到本地数据时,您似乎无法做到这一点。
【讨论】:
现在实际上支持分组与数据源一起使用。这是一个代码 sn-p,它将使用 Kendo UI 2015.3.1111 和 jQuery 1.9.1 创建一个下拉列表,按团队颜色分组。数据源candidates 是数据项的本地数组。下拉列表将替换页面上的一个 HTML 元素,<input id="victim"/>。
var candidates = [
{ "id": 1, "name": "Alice", "team": "Red" },
{ "id": 2, "name": "Bob", "team": "Red" },
{ "id": 3, "name": "Charlie", "team": "Blue" },
{ "id": 4, "name": "Dorothy", "team": "Blue" },
{ "id": 5, "name": "Ed", "team": "Green" },
{ "id": 6, "name": "Frances", "team": "Green" },
{ "id": 7, "name": "George", "team": "Purple" },
{ "id": 8, "name": "Helen", "team": "Purple" },
];
$("#victim").kendoDropDownList({
"dataTextField": "name",
"dataValueField": "id",
"dataSource": { "data": candidates, "group": "team" },
"index": 0
});
我之前没有注意到,但小部件也会对组进行排序。
【讨论】:
Kendo DropDownList 小部件不支持分组。
【讨论】: