jquery - How to set data values on Kendo Multi Select? -
i'm using kendo multi select. want load selected values multi select. how set data values in java script? have following script:
$('#selectedfilters').kendomultiselect({ datasource: data, datatextfield: 'name', datavaluefield: 'value', filter: 'contains', placeholder: "add filter", delay: 0, minlength: 2, highlightfirst: true, ignorecase: true, change: function (event) { applyfilters(); }, });
you can use value()
method setting values.
example, give following html:
<a href="#" id="button" class="k-button">select</a> <input id='selectedfilters'>
and javascript:
var data = [ { name : "name1", value : "value1" }, { name : "name2", value : "value2" }, { name : "name3", value : "value3" }, { name : "name4", value : "value4" }, { name : "name5", value : "value5" }, { name : "name6", value : "value6" } ]; var multiselect = $('#selectedfilters').kendomultiselect({ datasource : data, datatextfield : 'name', datavaluefield: 'value', filter : 'contains', placeholder : "add filter", delay : 0, minlength : 2, highlightfirst: true, ignorecase : true, change : function (event) { console.log("change"); } }).data("kendomultiselect"); $("#button").on("click", function () { console.log("multiselect", multiselect); multiselect.value(["value1", "value2", "value6"]); });
if click on button
multi-value input
gets: name1
, name2
, name6
.
edit if want add current selected values do:
$("#button").on("click", function () { var selected = multiselect.value(); var res = $.merge($.merge([], selected), ["value1", "value2", "value6"]); multiselect.value(res); });
note: sort of reason cannot reuse selected
array setting new values, should create new one.
check running here
Comments
Post a Comment