I have got this far
.Columns(columns =>{ columns.Command(commands => { commands.Select().ButtonType(GridButtonType.Text); }).Width(80).Title("Publish"); columns.Bound(o => o.Version).Width(80); columns.Bound(o => o.LastModified).Format("{0:dd-MM-yyyy hh:mm tt}"); columns.Bound(o => o.Published).Template(o => o.Published ? "Yes" : "No" );The grid loads ok however the template hasn't been applied. Can anyone see what I am doing wrong?
Thanks
Shane
8 Answers, 1 is accepted
Try this:
Template(o =>
{
%>
<%= o.Published ? "True" : "False" %>
<%
});
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Sorry forgot to mention that im using razor. So your example wont work for me.
The Razor syntax is this:
.Template(@<text>
@(item.Published ? "True" : "False")
</text>);
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Is this a bug with the latest release? as I have tried to use your suggestion however im only seeing either true or false
My binding of the columns looks like this
.Columns(columns => { columns.Bound(o => o.ID).ClientTemplate("<a href='" + Url.Content("~/businessaccount/publish/<#= ID #>") + "' class='t-button t-grid-select'>Publish</a>").Title("Publish").Width(80); columns.Bound(o => o.Version).Width(80); columns.Bound(o => o.LastModified).Format("{0:dd-MM-yyyy hh:mm tt}"); columns.Bound(o => o.Published).Template(@<text> @(item.Published ? "True" : "False") </text>); })There is no bug. The code is explicitly returning "True" or "False". I now see that you wanted "Yes" or "No" to be displayed. To do so just change the strings:
.Columns(columns => { columns.Bound(o => o.ID).ClientTemplate("<a href='" + Url.Content("~/businessaccount/publish/<#= ID #>") + "' class='t-button t-grid-select'>Publish</a>").Title("Publish").Width(80); columns.Bound(o => o.Version).Width(80); columns.Bound(o => o.LastModified).Format("{0:dd-MM-yyyy hh:mm tt}"); columns.Bound(o => o.Published).Template(@<text> @(item.Published ? "Yes" : "No") </text>); })Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
My full code for my grid looks like
@{ Html.Telerik().Grid<SP.Models.WebPageModel>().Name("Grid").DataKeys(dataKeys => dataKeys.Add(c => c.WebPageID)).ClientEvents(e => e.OnLoad("Grid_OnLoad")).ToolBar(commands => commands.Custom().ButtonType(GridButtonType.Text).Action("create", "webpage").Text("Create Web Page").ImageHtmlAttributes(new { style = "margin-left:0" })).Columns(columns =>{ columns.Bound(o => o.ID).ClientTemplate("<a href='" + Url.Content("~/businessaccount/publish/<#= ID #>") + "' class='t-button t-grid-select'>Publish</a>").Title("Publish").Width(80); columns.Bound(o => o.Version).Width(80); columns.Bound(o => o.LastModified).Format("{0:dd-MM-yyyy hh:mm tt}"); columns.Bound(o => o.Published).Template(@<text> @(item.Published ? "Yes" : "No") </text>);}).DataBinding(dataBinding => dataBinding .Ajax() .Select("GetWebPages", "BusinessAccount", new { id = (string)ViewData["id"] }) ).Sortable().RowAction(row => row.Selected = row.DataItem.WebPageID.Equals(ViewData["id"])).Pageable().Footer(true).Render(); }
Do I need to reference some other js library or something to enable changing the template?
Your grid seems to be ajax bound (this was not specified before)- server templates are not applied during ajax binding and you need to use a client template:
.ClientTemplate("<#= Published? 'Yes' : 'No' #>")
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
columns.Bound(x => x.Active).ClientTemplate("#= Active? 'Yes' : 'No' #");