This is a migrated thread and some comments may be shown as answers.

Set Values to Multiselect dynamically

5 Answers 1307 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Suk
Top achievements
Rank 1
Suk asked on 14 Mar 2015, 10:26 AM
I am new to kendo and I recently started coding in C#.net MVC. I have a JSON array in jsonObj(variable name), like for example:

'[{"key":"Name","comparison":"Equals","values":["JOHN","LILY"]}]' which is coming from database(controller) as a string...So, I used 
var jsonObj = $.parseJSON(dataItem.Data);
So, I got back the previous array string... where values contain the kendo multiSelect values....
Now I want this `jsonObj.values` to be set into the kendo multiSelect on a button click. I can see the values in alert as JOHN,LILY for alert(jsonObj.values);.
I coded:

$("#DrugNames").data("kendoMultiSelect").value(jsonObj.values);
$("#DrugNames").data("kendoMultiSelect").value(jsonObj.values.toString().split(','));

But nothing seems to work... I also tried using:

$("#DrugNames").data("kendoMultiSelect").value(["ABC","ASH"]);

Still no success. Please let me know where am I wrong.. Thanks in advance...

5 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 17 Mar 2015, 09:06 AM

Hello Sukanya,

 

The Kendo UI MultiSelect widget will accept an array of values for its value method. Please check the following sample and let me know if it helps:

http://dojo.telerik.com/UpoHA

 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Suk
Top achievements
Rank 1
answered on 19 Mar 2015, 12:19 PM
Thank you for your response Kiril .I followed your codes. And I understood what you are trying to say...
But,still it didn't work. 
I have '[{"key":"Name","comparison":"Equals","values":["JOHN","LILY"]}]' as a string in my DB. So, I used $.parseJSON(that string from DB) and changed it back to JSON array... and stored it in 'jsonObj' variable.

The multiSelect is in a window.. So, if I have "key"=="Name" pick the "Values" part and place it in the multiSelect...
So, I coded as 
$("#Names").data("kendoMultiSelect").value(jsonObj.values);

I dont undeerstand where am I wrong??? Please help.
0
Accepted
Kiril Nikolov
Telerik team
answered on 23 Mar 2015, 10:06 AM

Hello Sukanya,

Can you please edit the example that I provided and send it back in order for me to reproduce the exact issue and provide you with a solution? As I got a bit confused on what exactly your scenario is and what we can do in order to make it work.

Thanks for the cooperation.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Suk
Top achievements
Rank 1
answered on 24 Mar 2015, 11:59 AM
Thank you for your response Kiril... I was able to solve the problem... You see my JSON string was '[{"key":"Name","comparison":"Equals","values":["KIARA","JOHN","JOSH","JASON J","LILY"]}]'. So, I had to remove the `[` and `]` from both the ends and change it to JSON array using `JSON.parse()`... and then applied your technique to place the values in multiSelect.

I am sending you the link, which is as the below...
http://dojo.telerik.com/UpoHA/26
0
Kiril Nikolov
Telerik team
answered on 26 Mar 2015, 09:15 AM

Hello Sukanya,

Happy to hear that the problem is resolved. In case you have any further question, please do not hesitate to contact us.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
General Discussions
Asked by
Suk
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Suk
Top achievements
Rank 1
Share this question
or