This is a migrated thread and some comments may be shown as answers.

[Solved] Format not working

8 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Steve
Top achievements
Rank 1
Steve asked on 12 Dec 2009, 09:16 PM
I'm using Grid as per the sample.
ie. 
column.Add(c => c.TheValue).Format("{0}").Title("Sample"); 
                     

And it's returning "{0}"

8 Answers, 1 is accepted

Sort by
0
Chris Williams
Top achievements
Rank 1
answered on 12 Dec 2009, 09:51 PM
Hi,

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


0
Steve
Top achievements
Rank 1
answered on 12 Dec 2009, 10:59 PM
I need to pass the string in -it's not formatted:

columns.Add(c => c.CustomerID).Format( 
                Html.ActionLink("Edit", "Home", new { id = "{0}"}}) 
            ).Encoded(false).Title("Edit"); 

As per documentation, it should pass CustomerID to the id as the value
0
Chris Williams
Top achievements
Rank 1
answered on 13 Dec 2009, 01:07 AM
I see.  I think I read that you could use format for that, but I built it a different way:

columns.Add(c => 
                        {  
                            %> 
                                <%= Html.ActionLink("Details", "Details", new { id = c.CustomerId })%> | 
                                 <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"



0
Steve
Top achievements
Rank 1
answered on 13 Dec 2009, 01:26 AM
That is not possible when using Ajax unfortunately.  They don't support templates for that just format (yet).

Not sure exactly why and I look forward to them adding that support because it's much easier and consistent to work with.

ie.documentation:
"Currently templated columns are supported only in Server Binding mode. Client-side templates will be implemented in a future release. As a workaround you can use the Format method like this:"
0
Atanas Korchev
Telerik team
answered on 14 Dec 2009, 08:39 AM
Hi guys,

 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.
0
Steve
Top achievements
Rank 1
answered on 14 Dec 2009, 12:35 PM
Thank you.

What about jTemplates ?

(There is a value I see here in jTemplates - this would seemly not interfere with the current webforms engine markup right ?)

The syntax looks very straight forward as well.

Thanks for the explanation - I'm glad to see the use of json here - I had initially thought it was using partial views and sending the html  vs. json


0
Atanas Korchev
Telerik team
answered on 14 Dec 2009, 02:04 PM
Hello Steve,

 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.
0
Steve
Top achievements
Rank 1
answered on 14 Dec 2009, 02:18 PM
Sounds good - going with what John Resig does is not a bad way to go  :)

I do think moving to this template based approach is the right direction, and thank you for the explanations.

This team is doing a fantastic job and I've enjoyed working with the library, I look forward to seeing more of what you can do.  The overall structure provided has been good.

Thanks again!
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Chris Williams
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or