[英]How to Make a Conditional Button in Kendo UI Grid ClientTemplate?
I have two columns in my grid, 我的网格中有两列,
columns.Bound(c => c.EndDateTime).Format(value: "{0:d}").Title(text: "End");
columns.Bound(c => c.LeaveRequestId).ClientTemplate("<a href='" + Url.Action(actionName: "Edit", controllerName: "Leave") + "/#= LeaveRequestId #' class='btn btn-primary btn-xs'>Edit</a>").Title(text: " ").Width(pixelWidth: 50);
What I want to do is have the edit button (second row of code) display a button when current time is still before EndDateTime. 我想做的是,当当前时间仍在EndDateTime之前时,让编辑按钮(第二行代码)显示一个按钮。 I don't know if it is better to have javascript inside the ClientTemplate, or to have a function at the bottom, and how it would work. 我不知道在ClientTemplate中放置javascript还是在底部放置一个函数,效果如何,是否更好。
Thanks! 谢谢!
This should work: 这应该工作:
columns.Bound(c => c.LeaveRequestId)
.ClientTemplate(
"# if ((new Date()) < EndDateTime) { #" +
"<a href='" + Url.Action(actionName: "Edit", controllerName: "Leave") + "/#= LeaveRequestId #' class='btn btn-primary btn-xs'>Edit</a>" +
"# } #"
)
.Title(text: " ")
.Width(pixelWidth: 50);
You could put the comparison inside a function, but that is up to you(and could depend on how complicated the comparison logic is). 您可以将比较放入函数中,但这取决于您(并且可能取决于比较逻辑的复杂程度)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.