Andrew McKeighan
Andrew McKeighan

Reputation: 131

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!

Upvotes: 0

Views: 1115

Answers (1)

The Dread Pirate Stephen
The Dread Pirate Stephen

Reputation: 3169

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

Upvotes: 1

Related Questions