[英]How to call javascript method from ClientTemplate in Kendo grid?
Is it possible to put in the ClientTemplate of Kendo grid a javascript statement? 是否可以在Kendo网格的ClientTemplate中添加一个javascript语句? I would like to calculate some data on the client and then to put the result in the row. 我想在客户端上计算一些数据,然后将结果放在行中。
I tried this: 我试过这个:
columns.Bound("ExecutionStartDateTime").Title("SummaryLine").Width("20%").ClientTemplate("<script> scheduleForm.generateSummary(#= ExecutionStartDateTime #, 2); </script>");
However, it gave no effect. 但是,它没有任何效果。
You can, with template literal syntax: 您可以使用模板文字语法:
<script>
function someFuntion(date) {
var result = "";
// Do whatever you need here (make ajax call etc..) and return result as html string
return result;
}
</script>
And bound your column as: 并将您的列绑定为:
columns.Bound("ExecutionStartDateTime").Title("SummaryLine").Width("20%")
.ClientTemplate("#=someFuntion(ExecutionStartDateTime)#");
// you can even pass 'data' implicit template parameter and extract ExecutionStartDateTime from there
You can even write inline javascript simply using # if(...){# ... #}# syntax. 您甚至可以使用#if(...){#...#}#syntax编写内联javascript。 This faq will help you. 这个常见问题将帮助您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.