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

DataSource with special characters (JSON)

5 Answers 1209 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lars Adler
Top achievements
Rank 1
Lars Adler asked on 24 May 2012, 11:25 AM
hello,
the datasource is a valid json but i can't get the grid to display the data (see below).
am i doing something wrong  or is it not supposed to work?
thankful for any Help!
viktor

var dataSet = [
 {
"Id": "datatests/57238",
"Name": "11hacAMT02",  
"Total|Fam": 96,
"Total|Mean": 2.4,
"Total|N1": 21,
"Total|TixP": 57,
"Filter Like|Var": 1.1,
"Age__25-29_Fam":89
 },
];
var layout =  [
{
field: "Name",
title: "Name"
},  
{
field: "Total|N1", //Uncaught ReferenceError: Total is not defined
title: "Total<br>N1"
},
{
field: "Filter Like|Var", //Uncaught Error: Invalid template
title: "Filter Like<br>Var"
},
{
 field: "Age__25-29_Fam", //Uncaught Error: Invalid template 
 title: "Age 25-29<br>Fam"
}
];
var localDataSource = new kendo.data.DataSource({ data: dataSet });
$("#grid").kendoGrid({
dataSource: localDataSource,
columns:layout                    
});

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 25 May 2012, 09:41 AM
Hi Lars,

 The Kendo UI Grid requires column fields to be valid JavaScript identifiers. It generates a row template like this <td>#= field #</td>.

In your case the template would look like <td>#= Total|Fam #</td> which is not valid JavaScript code.

I suggest you rename the fields in your JSON response. You can set the title of the grid columns to the required value though:

columns: [
     { field: "totalFam", title: "Total|Fam" }
]

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
joshua
Top achievements
Rank 1
answered on 12 Aug 2012, 05:35 AM
Ok so im not understanding how a template that breaks under the data served to it is a correct model... I would think it would be easier to have the template format a unique ID per the data and remove special text then have it just fail.... you never know whats going to be included in the data.

This would be a deal breaker... the template needs to be self contained and not break from data....
0
joshua
Top achievements
Rank 1
answered on 15 Aug 2012, 05:49 PM
I did a detailed walk through of the issue if you have not figured it out.

http://www.kendoui.com/forums/framework/data-source/uncaught-referenceerror-uid-is-not-defined.aspx#2232872 
0
Ed
Top achievements
Rank 1
answered on 15 Sep 2014, 04:43 AM
I have a problem with special characters. 

<div><span
class="mob-col-title">Categor&#237;a:</span>
#=CategoryName#</div>

' Generated code:'var
o,e=kendo.htmlEncode;with(data){o='\n
<div><span
class="mob-col-title">Categor&';237;a:</span>
;o+='=CategoryName';</div>









0
Alex Gyoshev
Telerik team
answered on 15 Sep 2014, 10:01 AM
Hello Ed,

When using the # character in templates, it needs to be escaped -- otherwise it will be handled like template logic:

<div><span class="mob-col-title">Categor&\#237;a:</span>#=CategoryName#</div>

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Lars Adler
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
joshua
Top achievements
Rank 1
Ed
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or