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

[Solved] Handle Formatting of Column in Method

6 Answers 105 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.
Gabe
Top achievements
Rank 1
Gabe asked on 28 Apr 2011, 03:34 PM
This is what I originally had, but I want to conditionally handle the formatting.

.Format("{0:MM/dd/yyyy}")

If DateTime == DateTime.Min then I want to show an empty value rather than DateTime.Min...

So...
I have created and Extension Method to handle my DateTime formatting...
How can I pass in the value correctly to the method for the grid...

Example:

On one of my columns I have the Telerik Format method where I want to call my extension method to do the formatting, I thought this might work but instead its passing in the literal "{0}"

.Format(Html.FormatDateTime("{0}"))


How can I pass in the correct value ?

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 28 Apr 2011, 03:37 PM
Hello Gabe,

 The format accepts only strings. If you have a custom formatting method you must set the Template for your column:

 column.Bound(d => d.Date).Template((d) =>
{
   %>
  <%= Html.FormatDateTime(d.Date) %>
});

Have in mind though that this will only work for server bound grids.

Regards,
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
0
Gabe
Top achievements
Rank 1
answered on 28 Apr 2011, 03:42 PM
I am using Client Side Binding, how can I do this using Client Side Binding?
0
Atanas Korchev
Telerik team
answered on 28 Apr 2011, 03:54 PM
Hi Gabe,

 You cannot do this via client-side binding because there is no way to use server side method in the browser. You have to create a client-side template which will format the date properly or just use a custom date format for your column.

Regards,
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
0
Gabe
Top achievements
Rank 1
answered on 28 Apr 2011, 03:57 PM
So the clientside template would have to use some script to format the date, I tried that... But didn't pan out...

Here's what I tried..

.ClientTemplate("<script>formatDateTime('<#= EffectiveDate #>')</script>")

The value ends up blank in the cell...
0
Gabe
Top achievements
Rank 1
answered on 28 Apr 2011, 04:28 PM
I got it to work like this:

.ClientTemplate("<#= formatDateTime(EffectiveDate) #>")


Is this a good approach?
0
Accepted
Atanas Korchev
Telerik team
answered on 28 Apr 2011, 04:40 PM
Hi Gabe,

 Yes, this is the best approach.

Regards,
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
Tags
Grid
Asked by
Gabe
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gabe
Top achievements
Rank 1
Share this question
or