JSON Data Source Issue

4 posts, 0 answers
  1. Hung Hong
    Hung Hong avatar
    2 posts
    Member since:
    Sep 2016

    Posted 13 Mar 2017 Link to this post

    Hi, 
    I'm working on MultiSelect + JSON as data source, i'm having issue to display the json result in Multiselect. 
    It display to me as undefined.

    Below is my multiselect code

                var multiselect = $("#ddlSelectCostCenter").data("kendoMultiSelect")
                var dataSource = new kendo.data.DataSource({
                    data: [],
                    pageSize: 500
                });
                multiselect.setDataSource(dataSource);
                 
                if (result !== "") {
     
                    dataSource = new kendo.data.DataSource({
                        type:"json",
                        data: JSON.stringify(result),
                        pageSize: 500              
                    });
     
                    multiselect.setDataSource(dataSource);
                    multiselect.dataTextField = "Name";
                    multiselect.dataValueField = "Value";
    }

     

    My Json is like below. 
    [{"Value":"0000","Name":"ALL"},{"Value":"0111","Name":"0111 ~ Facility Management"},{"Value":"0113","Name":"0113 ~ NP Logistics Setup"},{"Value":"1001","Name":"1001 ~ TV KL Tec President Office"},{"Value":"2001","Name":"2001 ~ North Chip Engineering"},{"Value":"2002","Name":"2002 ~ TV AM CHIP"},{"Value":"2003","Name":"2003 ~ AutoMount Metecon"},{"Value":"2004","Name":"2004 ~ HM Office"},{"Value":"2005","Name":"2005 ~ BOARD BIZ-HM Office"},{"Value":"2006","Name":"2006 ~ Sony MFC Sys"},{"Value":"2007","Name":"2007 ~ AM North Oth"},{"Value":"2009","Name":"2009 ~ TV AM Office"},{"Value":"2010","Name":"2010 ~ AM North DISC"},{"Value":"2011","Name":"2011 ~ AM North CHIP"}]

    What do I missed out?

    Thank

     

     

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1951 posts

    Posted 14 Mar 2017 Link to this post

    Hello Hung Hong,

    "json" is not a valid type for the Kendo DataSource. Here's a sample dojo that works at my end. The json array is passed directly to the DataSource's data configuration option.

    Regards,
    Ivan Danchev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Hung Hong
    Hung Hong avatar
    2 posts
    Member since:
    Sep 2016

    Posted 15 Mar 2017 Link to this post

    Hi Ivan,

    Thank for the reply. Your sample work! But there are some thing required your help.

    1. How do I convert my json output to json array? As I work with an api that return the result to me in json.

     

    Thank

     

     

     

  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1951 posts

    Posted 16 Mar 2017 Link to this post

    Hello Hung Hong,

    You can convert it with jQuery:  $.parseJSON('[' + result + ']') Modified dojo example.

    Regards,
    Ivan Danchev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top