Reputation: 11
I want to change the button text on load of the page. I'm using static data and my button is not displayed.
Model
public class UserModel
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public long Phone { get; set; }
public bool IsActive { get; set; }
}
Controller
List<UserModel> listuser = new List<UserModel>();
UserModel users = new UserModel();
users.Firstname = "Nisha mam";
users.Lastname = "Patel";
users.Phone = 90897564444;
users.IsActive = true;
listuser.Add(users);
users = new UserModel();
users.Firstname = "Namrata";
users.Lastname = "Bhavsar";
users.Phone = 9678975643;
users.IsActive = false;
listuser.Add(users);
users = new UserModel();
users.Firstname = "Anjali";
users.Lastname = "Mehta";
users.Phone = 9228975643;
users.IsActive = true;
listuser.Add(users);
return View(listuser);
View
@Html.Kendo().Grid(Model).Name("List").Columns(c =>
{
c.Bound(p => p.Firstname);
c.Bound(p => p.Lastname);
c.Bound(p => p.Phone);
c.Bound(p => p.IsActive).Title("Unlock Payroll Entry").Filterable(false).ClientTemplate("<input type='submit' value='Unlock'></span>").Sortable(false);
})
Upvotes: 0
Views: 560
Reputation: 6013
The ClientTemplate
in a Kendo grid can include arbitrary javascript to execute which will allow you to build the html for your conditionally.
Try something like this for the binding on your IsActive
column.
c.Bound(p => p.IsActive)
.Title("Unlock Payroll Entry")
.Filterable(false)
.ClientTemplate(
"# if (IsActive) { #" +
"<input type='submit' value='Unlock' />" +
"# } else { #" +
"<input type='submit' value='SomeOtherValue' />" +
"#}#")
.Sortable(false);
Kendo also supports specifying a template like this one 'externally' (i.e. in a separate block that you refer to by name / id in your grid definition). This approach might be easier to work with for more complex javascript logic.
Upvotes: 1