Hi,
In my clientTemplate I try to do the following:
"<
div
style=\"display:#if(MimeType == 'application/pdf') {#block#} else {#none#}# \">" +
But when I compare to string it keept giving me an error
"Error: Invalid template:'"
and I treid a lot if different ways to do this.
If I compare to a boolean or integer it goes ok, but for some reason I can't get string compare to work.
Can someone help me out?
thank you.
5 Answers, 1 is accepted
Thank you for the provided code snippet. I used it to attempt to get the same error as you have, however to no avail:
.Columns(columns =>
{
columns.Bound(p => p.ShipName).ClientTemplate(
"<div style=\"display:#if(MimeType == 'application/pdf') {#block#} else {#none#}# \">Test</div>"
);
})
Here is the resulting HTML:
Something you can try is to pass a JavaScript function instead:
https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-use-javascript-functions-in-client-column-templates
If this does not help, please provide additional information - the model and grid declarations as well as a sample data item from the response so I can test with your scenario specifics. Look forward to your response.
Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Hello Alex,
the Javascript approach works for now.
thank you.
columns.Bound(o => o.RecordingPath).Width(115).HeaderTemplate("Recording").ClientTemplate("<audio controls='controls' onplay='RemoveMarker(<#=ID#>,<#=IsSeen#>)' id='player-<#=ID#>' style='width:100%' ><source src='<#=RecordingPath#>'' type='audio/mp3'></audio>").Sortable(true);
How i can add condition if RecordingPath is null then show a message no recording
Hi Muhammad,
I'd recommend using a function to return either 'No Record' or the html string to make it a bit clearer:
columns.Bound(p => p.RecordingPath).ClientTemplate("#=renderPlayer(data)#");
<script>
function renderPlayer(data) {
if (data.RecordingPath) {
return `<audio controls='controls' onplay='RemoveMarker(${data.ID}, ${data.IsSeen})' id='player-<${data.ID}>' style='width:100%' ><source src='<${data.RecordingPath}>' type='audio/mp3'></audio>`;
} else {
return 'No recording';
}
}
</script>
Best Regards,
Georgi Denchev
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/.