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

JSON Data Source Issue

3 Answers 425 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Hung Hong
Top achievements
Rank 1
Hung Hong asked on 13 Mar 2017, 09:55 AM

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

 

 

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 14 Mar 2017, 09:27 AM
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.
0
Hung Hong
Top achievements
Rank 1
answered on 15 Mar 2017, 07:04 AM

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

 

 

 

0
Ivan Danchev
Telerik team
answered on 16 Mar 2017, 12:54 PM
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.
Tags
MultiSelect
Asked by
Hung Hong
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Hung Hong
Top achievements
Rank 1
Share this question
or