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

Nullable column template

1 Answer 361 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 19 Jan 2016, 06:23 PM

Kendo Q3 2015, asp.net mvc 

 I have the scenario where I'm binding columns to nullable objects.  I'm using the client template, and have a little html to add if the value is not null.

I've simplied my code here.  "ChildObject" is a property that can be null.  If it is null, show nothing.  If it is not null, show ChildObject.Name (in some custom html)

columns.Bound(c => c.ChildObject.Name)
.Title("Some Column")                  
.ClientTemplate(                      
"#= (ChildObject == null) ? ' ' : '<div>' + ChildObject.Name + '</div>' #"                  
)                  
.Width(100);

This code throws the invalid template error.  If I remove the '+'s, it works fine. Example:  '<div>Hello</div>' works, however that wouldn't allow me to add databound text. 

Thanks

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 21 Jan 2016, 01:37 PM
Hi Justin,

Try this:

"# if (ChildObject != null) { #" +
"<div>#= ChildObject.Name #</div>" +
"#} else {#" +
"<div>None</div>" +
"# } #"


Regards,
Hristo Valyavicharski
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
Justin Lee
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or