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

Column Template with JS Reserved Word

2 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stacy
Top achievements
Rank 2
Stacy asked on 28 Aug 2013, 11:46 PM
I have a column in my grid defined as:

field : "class"
title : "Class"
width : 250
This works fine, but when I add a column template like so: 
template : "<div  class=\\"FieldValueLink\\"  onclick=\\"(function(e,obj){ /* do stuff */ })(event, this)\\" >#=class#</div>"
I get the following error: 

Uncaught Error: Invalid template:'<tr data-uid="#=data.uid#" role='row'><td role='gridcell'><div class="FieldValueLink" onclick="(function(e,obj){ /* do stuff */})(event, this)" >#=class#</div></td><td style="display:none" role='gridcell'>#:data.id==null?'':data.id#</td></tr>' Generated code:'var o,e=kendo.htmlEncode;with(data){o='<tr data-uid="'+(data.uid)+'" role=\'row\'><td role=\'gridcell\'><div class="FieldValueLink" onclick="(function(e,obj){ /* do stuff */ })(event, this)" >'+( class )+'</div></td><td style="display:none" role=\'gridcell\'>'+e(data.id==null?'':data.id)+'</td></tr>';}return o;' kendo.all.min.js:9

I'm sure this is because 'class' is a reserved word in javascript. Is there a different way to reference the field name in the template? 

We're just trying to convert our existing grids to kendo grids. I'd rather not alter my database and all the existing code referencing this if it can be helped. 

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 30 Aug 2013, 02:19 PM
Hello,

You can reference the field by using the template data in order to avoid the error:

#:data.class#
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Stacy
Top achievements
Rank 2
answered on 30 Aug 2013, 05:51 PM
That's what I was looking for, thanks. Could not find anything about this option in the docs or any of my searches.
Tags
Grid
Asked by
Stacy
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Stacy
Top achievements
Rank 2
Share this question
or