0

I am using Kendo UI (Multi Select Dropdown) and I want to change the option values of it from external script file.

This is working as expected {Online DEMO} only if I am not initializing the Kendo feature in html page.

So, I have already options in html page:

My HTML Page:

    <select id="multiselect" multiple="multiple" class="mySelectBox">
      <option>Option 1</option>
      <option>Option 2</option>
    </select>
    <select id="multiselect2" multiple="multiple">
      <option>Option 3</option>
      <option>Option 4</option>
    </select>

    <script language="Javascript">
      $("#multiselect, multiselect2").kendoMultiSelect();
    </script>

and trying to replace the values from external.js file as:

     var dataMultiselect = ["New Value 1", "New Value 2", "New Value 3"];
      $("#multiselect").kendoMultiSelect({
        dataSource: dataMultiselect
      });
      $("#multiselect2").kendoMultiSelect({
        dataSource: dataMultiselect
      });

It is not working... Any Help can save my day

Getting Error as "Uncaught TypeError: Cannot set property 'selected' of undefined"

Reddy
  • 1,477
  • 29
  • 79

1 Answers1

1

You can change data values with function setDataSource

var data2 = ["Five", "Six"];
var multiselect = $("#multiselect").data("kendoMultiSelect");
multiselect.setDataSource(new kendo.data.DataSource({ data: data2 }));  

Dojo example

Ademar
  • 1,418
  • 1
  • 17
  • 27
  • Hi **@Ademar**... almost there... but I am getting new values as 'undefined'... if it is same file, its working correctly – Reddy Dec 19 '15 at 16:11
  • ... **May be because of first data values are coming from another file (html file)?** – Reddy Dec 19 '15 at 16:18
  • Hm, so thats strange, On my computer it works also with external js file. Try yet add dataTextField and dataValueField properties into multiselect http://dojo.telerik.com/AkEke/4 ... but I am not giving much chances that it will change something... I will try think what can cause problem yet, but right now I have no idea.. – Ademar Dec 19 '15 at 16:28
  • Sorry again... no change as you said... One more thing is: I do not have control on changing the htmls... from HTML page: `` **And the script is:** `jQuery("#recipientSelect").kendoMultiSelect({ dataSource: data, filter: "contains" });` Anything wrong with the above code? – Reddy Dec 19 '15 at 16:54
  • And also in your latest example, default values are showing as "undefined" :( – Reddy Dec 19 '15 at 16:55
  • it looks correct ( http://dojo.telerik.com/AkEke/6 as you can see). I will try search yet and reproduce the problem. Is displaying any error browser's console or something (better chrome console than IE, i have figured out, that chrome console shows more) – Ademar Dec 19 '15 at 19:52
  • Hi **@Ademar**.. it is working as expected... but getting the 2 dropdowns with old values and new values... If I select "One" and "Two", not getting any error... If select other any value from default dropdown, I am getting the error as "Uncaught TypeError: Cannot set property 'selected' of undefined" – Reddy Dec 20 '15 at 21:31