3 Answers, 1 is accepted
I suggest that you use the value method of the Kendo UI Multiselect and pass an array of values as parameter. I believe the easiest approach that will work with any kind of binding, would be to:
1. Get the dataSource items
2. Filter them to get only the dataItems that should be selected
3. Get their value and pass it to the value method
I have prepared a dummy sample that illustrate the approach:
https://dojo.telerik.com/enUSIMUm
var
multiselect = $(
"#multiselect"
).data(
"kendoMultiSelect"
);
var
values = $(
"#multiselect"
).data(
"kendoMultiSelect"
).dataSource.data().filter(
function
(dataItem) {
return
dataItem.text ==
"Item1"
|| dataItem.text ==
"Item7"
;
}).map(
function
(item) {
return
item.value;
});
multiselect.value(values);
Let me know if such approach would fit to your scenario.
Regards,
Joana
Progress Telerik
Hi Joana,
finaly I solved it on other way. I dont't no it is worse or not but it works now. :)
$(function () {
$('#textarea').bind('paste',
function (e) {
var ctl = $(this);
var multiselect = $("#EmployeeIds").data("kendoMultiSelect");
setTimeout(function () {
//multiselect.search(ctl.val());
var items = multiselect.dataSource._data;
var list = ctl.val().replace(",", "\n").split("\n");
//alert(ctl.val());
var selected = multiselect.value();
var notSelected = [];
for (var j = 0; j < list.length; j++) {
for (var i = 0; i < items.length; i++) {
if (list[j].trim().toLowerCase() === items[i].DisplayName.split("(")[0].trim().toLowerCase()) {
selected.push(items[i].EmployeeId);
break;
}
if (i === items.length - 1)
notSelected.push(list[j].trim());
};
};
multiselect.value(selected);
multiselect.dataSource.filter({});
if (notSelected.length > 0) {
alert("Nem kiválasztott dolgozók:" + notSelected);
} else alert("Minden dolgozó kiválasztva!");
},
100);
//$("#EmployeeIds").getKendoMultiSelect().value(["74", "78"]);
});
});
Thanks, Karoly
Thank you for sharing your solution.
I am glad that you've managed to fulfill your scenario.
Regards,
Joana
Progress Telerik