我正在使用Kendo Grid来显示价值。现在我的一个基于某些条件的字段想要将文本显示为链接,该链接应该引用javascript函数。 以下是我的代码
columns =>
{
columns.Bound(r => r.RequestCode).Width(110);
columns.Bound(r => r.StaffId).Width(90);
columns.Bound(r => r.StaffName).Width(130);
columns.Bound(r => r.Company);
columns.Bound(r => r.RequestType).Width(90);
columns.Bound(r => r.NoofDays);
columns.Bound(r => r.TravelStartDate).Format("{0:dd-MMM-yyyy}").Width(130);
columns.Bound(r => r.TravelEndDate).Format("{0:dd-MMM-yyyy}").Width(130);
columns.Bound(r => r.SLADays).Width(90);
columns.Bound(r => r.AdvanceAmount).Width(130);
//columns.Bound(r => r.Installments);
columns.Bound(r => r.Installments).Width(90);
//columns.Bound(r => r.RecoveryAmount);
columns.Bound(r => r.RecoveryAmount).ClientTemplate("<span id='vatId'> #= VATAmount=kendo.toString((Installments == 0 ? 0 : AdvanceAmount/Installments), 'n0') # </span>" +
"<input type='hidden' class='VATAmount' value='#=kendo.toString( (Installments == 0 ? 0 : AdvanceAmount/Installments), 'n0')#' />").Width(130);
columns.Bound(r => r.WfStatusDesc).ClientTemplate("<a href=javascript:jsFoo(\'" + "#: RequestCode #" + "\')>#: WfStatusDesc #</a>").Title("Expense Status").Width(110);
columns.Bound(r => r.PaidAmount).Visible(false);
columns.Bound(r => r.DutyTravelID).Visible(false);
columns.Bound(r => r.StaffSeqNumber).Visible(false);
}
答案 0 :(得分:1)
您需要将模板定义为函数
<script>
function someFunction(data) {
if(data.wfstatusDesc == 'Approve')
return '<a href="#tips">'+data.wfstatusDesc+'</a>';
else
return '<div>Not approved</div>';
}
</script>
然后使用它:
.ClientTemplate("#=someFunction(data)#");