简体   繁体   English

如何在Kendo UI Grid ClientTemplate中创建条件按钮?

[英]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.

相关问题 Kendo UI Grid 在 ClientTemplate 中获取行 ID - Kendo UI Grid get Row Id in ClientTemplate 如何获得Kendo Grid ClientTemplate价值到Javascript - How To Get Kendo Grid ClientTemplate Value To Javascript 如何从Kendo网格中包含按钮的列中向ClientTemplate发送值? - How can I send a value from a column in a Kendo Grid containing a button to a ClientTemplate? 如何从Kendo网格中的ClientTemplate调用javascript方法? - How to call javascript method from ClientTemplate in Kendo grid? 如何使用angular js为kendo ui网格添加条件列? - How to add conditional column for kendo ui grid using angular js? Kendo mvc Grid ClientTemplate javascript 功能不起作用 - Kendo mvc Grid ClientTemplate javascript function not working Kendo UI Grid:如何有条件地动态添加“创建”按钮工具栏 - Kendo UI Grid : How to conditionally add a 'create' button toolbar dynamically 如何在Kendo-ui网格中制作actionlink / url.action - How to make actionlink/url.action in kendo-ui grid Kendo UI Grid:如何使单元格在条件下只读 - Kendo UI Grid: how to make cell read only on condition 在按钮上单击后,如何使用javascript发出请求并使用ajax MVC Kendo UI网格调用读取方法 - Upon button click how to make request using javascript and call read method by using ajax MVC Kendo UI grid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM