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

Client Template Advanced Formatting

2 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Veteran
Lee asked on 17 Feb 2021, 05:51 AM

Hi,

I'm trying to do an if like statement with the ClientTemplate Formatting, for basic usage this works:

#= (Location == "") ? 'N/A' : Location #

 

If the Location is empty it Displays N/A as needed, but if i try and make it a bit more advanced for another field i.e:

#= (AssignedToPhone == "") ? 'N/A' : '<a href="tel:AssignedToPhone" class="btn-link">AssignedToPhone</a>' #

 

I don't get any errors, but it renders as a link with the text as AssignedToPhone, how do i get it to show the actual value? I have also tried:

#= (AssignedToPhone == "") ? 'N/A' : '<a href="tel:#=AssignedToPhone#" class="btn-link">#=AssignedToPhone#</a>' #

 

This causing an error, and no render happens "Uncaught Error: Invalid template:' (then a bunch of HTML)"

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Lee
Top achievements
Rank 1
Veteran
answered on 18 Feb 2021, 04:47 AM

After relaxing for a bit and re thinking i could see the issue and here's the result:

#= (AssignedToPhone == "" || AssignedToPhone == null) ? 'N/A' : '<a href="tel:' + AssignedToPhone + '" class="btn-link">' + AssignedToPhone + '</a>' #

 

Now prints N/A if empty or null otherwise it prints a hyperlink with the phone number! :)

 

0
Accepted
Tsvetomir
Telerik team
answered on 19 Feb 2021, 06:15 PM

Hi Lee,

Thank you for sharing the latest version that you have undertaken in order to resolve the case with our community. 

Indeed, for more complex scenarios, you could make use of a JavaScript function to handle the template.

https://docs.telerik.com/kendo-ui/framework/templates/overview#handling-external-templates-and-expressions

In the current case, it would be similar to:

.ClientTemplate("#=myFunc(data)#") // where the data is the data item for the current row

 

Kind regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Lee
Top achievements
Rank 1
Veteran
Answers by
Lee
Top achievements
Rank 1
Veteran
Tsvetomir
Telerik team
Share this question
or