Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear selected value(s) for Kendo multi select

I have Kendo multiSelect control which is working perfectly fine. However I am facing issue to reset its selected value. The following is what I have tried so far :

$("#Department option:selected").removeAttr("selected");  

And

var departmentMultiselect = $('#Department').data("kendoMultiSelect");
var subtract = $('#department').val();
                var values = departmentmultiselect.value().slice();
                values = $.grep(values, function (a) {
                 return $.inarray(a, subtract) == -1;
                });
                departmentmultiselect.datasource.filter({});
                departmentmultiselect.value(values);  

In the second code, control bypasses the following code

values = $.grep(values, function (a) {
                     return $.inarray(a, subtract) == -1;
                    });  

How can I reset this control?

like image 847
Nitish Avatar asked Nov 07 '13 12:11

Nitish


2 Answers

To unselect all values in kendo multiselect:

var multiSelect = $('#Department').data("kendoMultiSelect");
multiSelect.value([]);
like image 93
Mekanik Avatar answered Sep 19 '22 02:09

Mekanik


I had this same question, but wanted to remove only one value from the multiselect rather than everything. This is what I came up with:

var multiselect = $('#multiSelectId').data("kendoMultiSelect");
var values = multiselect.value().slice();

// optionId is the value I want to remove
var index = $.inArray(optionId, values);
if (index > -1) {
    values.splice(index, 1);
}

multiselect.dataSource.filter({});
multiselect.value(values);
like image 24
Warr1611 Avatar answered Sep 20 '22 02:09

Warr1611