sir*_*ask 5 jquery telerik kendo-ui
我有一个多选剑道,由mvc中的控制器填充.
我在下拉列表中有一个选项是selectAll,当我选择该选项时,我清除所有其他选项,现在我想禁用下拉列表(但不是删除"全选"选项的选项).
如果我做
multiselect.enable(false) //i lose the option to delete the selected "Select All"
Run Code Online (Sandbox Code Playgroud)
使用以下代码:当我选择"全选"选项时,我清除所有选择的其他选项和剑道,只需选择所有选项.
if (sel == 'Select All') {
var name_Controller = $(e.item).parent().attr('id');
var name_Controller = name_Controller.substr(0, name_Controller.indexOf('_'));
var t = "#" + name_Controller;
var required = $(t).data("kendoMultiSelect");
required.value(""); // to clean
Run Code Online (Sandbox Code Playgroud)
现在..我如何禁用其他选项,或者知道已经选择的选项的名称,以便执行以下操作:
if(required.contains("Select All")) //dont do nothing
Run Code Online (Sandbox Code Playgroud)
required.val()doenst工作,因为它被用于多个下拉列表,所有下拉列表都自动使用不同的id
有两个问题需要记住:
filter.change事件,以便您可以分析选择了哪些选项,如果选择“全选”,则过滤列表中的每个选项。你应该做的是这样的:
var multi = $("#colors").kendoMultiSelect({
dataSource: [
{ name: "Select All" },
{ name: "Red" },
{ name: "Green" },
{ name: "Blue" }
],
dataTextField: "name",
dataValueField: "name",
change: function(e) {
// Get selected options
var values = this.value();
if ($.inArray("Select All", values) != -1) {
// If "Select All" is in the list
// Remove other possibly selected options
multi.value("Select All");
// Remove any option from the datasource
multi.dataSource.filter({ field : "name", operator : "eq", value : "Select All"});
} else {
// Clean filter
multi.dataSource.filter({ });
}
}
}).data("kendoMultiSelect");
Run Code Online (Sandbox Code Playgroud)
在这里检查: http: //jsfiddle.net/OnaBai/9nVdq/6/
编辑:如果您想做一个通用函数来处理此“全选”,您应该将 MultiSelects 定义为:
var multi = $("#colors").kendoMultiSelect({
dataSource: colors,
dataTextField: "name",
dataValueField: "name",
change: selectAll
}).data("kendoMultiSelect");
$("#cities").kendoMultiSelect({
dataSource: cities,
dataTextField: "name",
dataValueField: "name",
change: selectAll
});
Run Code Online (Sandbox Code Playgroud)
函数selectAll为:
function selectAll(e) {
// Get selected options
var values = this.value();
if ($.inArray("Select All", values) != -1) {
// If "Select All" is in the list
// Remove other possibly selected options
this.value("Select All");
// Remove any option from the datasource
this.dataSource.filter({ field : "name", operator : "eq", value : "Select All"});
} else {
// Clean filter
this.dataSource.filter({ });
}
}
Run Code Online (Sandbox Code Playgroud)
“技巧”是this指 current multiselect。
在这里查看它的实际效果:http ://jsfiddle.net/OnaBai/9nVdq/8/
| 归档时间: |
|
| 查看次数: |
16574 次 |
| 最近记录: |