Set Values to Multiselect dynamically

6 posts, 1 answers
  1. Suk
    Suk avatar
    15 posts
    Member since:
    Mar 2015

    Posted 14 Mar 2015 Link to this post

    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...
  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 17 Mar 2015 Link to this post

    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!
     
  3. Suk
    Suk avatar
    15 posts
    Member since:
    Mar 2015

    Posted 19 Mar 2015 Link to this post

    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.
  4. Answer
    Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 23 Mar 2015 Link to this post

    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!
     
  5. Suk
    Suk avatar
    15 posts
    Member since:
    Mar 2015

    Posted 24 Mar 2015 in reply to Kiril Nikolov Link to this post

    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
  6. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 26 Mar 2015 Link to this post

    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!
     
Back to Top