Does anyone know why the following doesn't work right? I know for sure that "HasNotes" returns true for some records, but the following code never meets the "true" condition. Thanks!
template: "#=HasNotes#" == "true" ? "<a href=\"javascript:void(0)\" onclick=\"openNotes(#=CustomerKey#, #=ReservationKey#)\">View Notes</a>" : "N/A"
template: "#=HasNotes#" == "true" ? "<a href=\"javascript:void(0)\" onclick=\"openNotes(#=CustomerKey#, #=ReservationKey#)\">View Notes</a>" : "N/A"
3 Answers, 1 is accepted
0
Hi Grady Dycus,
The condition should be embedded in the template string itself.
In addition, I would like to recommend using ${} for your case.
Greetings,
Petyo
the Telerik team
I think that what you are trying to accomplish should look like this:
template:
'#if (HasNotes) {# <a href="javascript:void(0)" onclick="openNotes(${CustomerKey}, ${ReservationKey})">View Notes</a> #} else {# N/A #}#'
The condition should be embedded in the template string itself.
In addition, I would like to recommend using ${} for your case.
Greetings,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Thomas
commented on 28 Nov 2011, 01:23 PM
Top achievements
Rank 1
@Petyo:
Where (in which scope) would you define
??
Where (in which scope) would you define
function openNotes(CustomerKey, ReservationKey)
template:
'#if (HasNotes) {# <a href="javascript:void(0)" onclick="openNotes(${CustomerKey}, ${ReservationKey})">View Notes</a> #} else {# N/A #}#'
??
Petyo
commented on 28 Nov 2011, 02:31 PM
Telerik team
Hello Thomas,
Petyo
the Telerik team
You can pass the function reference as a parameter to the template. See this example - http://jsfiddle.net/yfqvM/13/.
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
ulises
commented on 14 Feb 2018, 12:22 AM
Top achievements
Rank 1
How can i implement these template in a command?
command:{ text: "Work", field: "Coment", click: function (e) { console.log("Hello")},template:'#if(Comentario != 0){# <a href="\\#" class="k-button k-button-icontext k-grid-Work"><span class="fa fa-2x fa fa-pencil-square-o text-default"></span></a> # } else {# <a href="\\#" class="k-button k-button-icontext k-grid-Work"><span class="fa fa-2x fa fa-pencil text-default"></span></a> #} #',},
0
In addition to that, it also works if the function is visible at of the template definition.
http://jsfiddle.net/yfqvM/14/
Kind regards,
Petyo
the Telerik team
http://jsfiddle.net/yfqvM/14/
Kind regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Hi Ulises,
Based on the provided information I assume that the requirement is to add a template to a command. Currently the commands do not have a template property.
As a workaround it is possible to iterate through the rows within the dataBound event handler and set the template of the column based on a condition.
e.g.
Below you will find a sample which demonstrates the above solution:
Regards,
Georgi
Progress Telerik
Based on the provided information I assume that the requirement is to add a template to a command. Currently the commands do not have a template property.
As a workaround it is possible to iterate through the rows within the dataBound event handler and set the template of the column based on a condition.
e.g.
dataBound:
function
(){
var
grid =
this
;
this
.tbody.find(
'tr'
).each(
function
(_,x){
var
dataItem = grid.dataItem(x);
if
(dataItem.Comentario != 0){
$(x).find(
'.k-grid-Work'
).html(
'<span class="fa fa-2x fa fa-pencil-square-o text-default"></span>'
)
}
else
{
$(x).find(
'.k-grid-Work'
).html(
'<span class="fa fa-2x fa fa-pencil text-default"></span>'
)
}
})
}
Below you will find a sample which demonstrates the above solution:
Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.