Changing the value of the Kendo Multiselect parameter

I have this weird multi-zone kendo issue.

<input id="addTags" /><br>
<input type="button" onclick="fillaList();" value="fill List" />
<input type="button" onclick="clearList();" value="Init List" />

var list=[{label:'tag1', value:'1'},
         {label:'tag9', value:'9'},
         {label:'tag8', value:'8'},
         {label:'tag7', value:'7'},
         {label:'tag6', value:'6'},
         {label:'tag5', value:'5'},
         {label:'tag4', value:'4'},
         {label:'tag3', value:'3'},
         {label:'tag2', value:'2'}];

function fillData(tagIds){ 

    var tagObj = $("#addTags").data("kendoMultiSelect");
    if (tagObj == undefined) { // if not loaded
        $("#addTags").kendoMultiSelect({
            dataTextField: "label",
            dataValueField: "value",
            dataSource: list,
            value: tagIds, placeholder: "Select from list",
            change: function() {
                // change
            }
        });
    } else { // if already loaded only change the values.
        tagObj.value(tagIds);
        console.log(tagIds);
        console.log(tagObj.value());
    }
}
function fillaList(){
    var tagIds=[1,2,3];
    fillData(tagIds);
}
function clearList(){
    fillData([]);
}

http://jsfiddle.net/ruchan/AgV52/1/

Replication problem

  • Click on the Initial List , and then add a new tag to the keyboard field .

  • click the fill list button . all values ​​not selected. or sometimes only 1 is selected

this problem is not present when choosing with the mouse.

I tested in Chrome v32.0.1700.107 m

+3
source share
1 answer

Before setting new values ​​in multi select, you must clear the filter to tagObj.dataSource.filter({});

Your function should be:

function fillData(tagIds){ 

    var tagObj = $("#addTags").data("kendoMultiSelect");
    if (tagObj == undefined) { // if not loaded
        $("#addTags").kendoMultiSelect({
            dataTextField: "label",
            dataValueField: "value",
            dataSource: list,
            value: tagIds, placeholder: "Select from list",
            change: function() {
                // change
            }
        });
    } else { // if already loaded only change the values.
        // Clean DataSource filter before setting new values
        tagObj.dataSource.filter({});
        tagObj.value(tagIds);
        console.log(tagIds);
        console.log(tagObj.value());
    }
}

JSFiddle : http://jsfiddle.net/OnaBai/AgV52/2/

+4

All Articles