简体   繁体   中英

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. 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM