8 Answers, 1 is accepted
You need something like this:
| columns.Add(c => c.LastSaleDate).Format("{0:d}" |
Here, d is one of the standard formats for Date values. You can use one of the other standard formats for other datatypes, or roll your own custom format, such as:
| .Format("{0:'$L '#,##0}") |
Chris
| columns.Add(c => c.CustomerID).Format( |
| Html.ActionLink("Edit", "Home", new { id = "{0}"}}) |
| ).Encoded(false).Title("Edit"); |
| columns.Add(c => |
| { |
| %> |
| <%= Html.ActionLink("Details", "Details", new { id = c.CustomerId })%> | |
| <a onclick="deleteRecord(<%= c.CustomerId %>)" href="#">Delete</a> |
| <% |
| }).Title("Actions").Width(100).HtmlAttributes(new { @style = "text-align:center" }).HeaderHtmlAttributes(new { @style = "text-align:center" }); |
This is essentially just creating a column and adding text to it. When this runs, there is a single "Actions" column that has two links: "Edit | Delete"
I want to shed some light on why templates don't work in ajax or webservice binding mode.
Templates currently are just an Action which upon execution outputs some HTML. In ajax mode however the grid is not rendered server-side. Instead JSON data is transferred back and forth. The grid then binds to that JSON data using JavaScript. Since there is no straight forward conversion from C# to JavaScript the server-side template cannot be translated verbatim to JavaScript which can then be used for client-side templating. The workaround currently is to use the Format feature and embed the template as string. This works with the only limitation that you ca use only the data field to which the column is bound to. To solve this limitation we plan to implement client-side templates. Maybe something like this.
I hope this helps,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
jTemplate was one of the libraries we evaluated. However we would most likely pick the solution of John Resig as it is very lightweight and quite powerful. I think we know how to avoid the problem with it using server-side tags ( <%=).
Regards,
Atanas Korchev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.