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

Formatting all dates

3 Answers 20 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.
Rickard
Top achievements
Rank 1
Rickard asked on 31 Oct 2011, 08:31 AM
Hello. I have a grid that shows some data from a database, just the essentials, and there i've formatted my dates by binding each column manually and applying a format to it.

However, i also have a detailed view, in which the grid is filled with obscene amounts of data, and binding each and every column just so i can get the dates to show in a proper format isn't very practical.

Is there any way to format all dates output by the MVC Grid in a particular fashion? Say yyyy-MM-dd?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 31 Oct 2011, 05:06 PM
Hi Rickard,

 The only built-in way to customize the format of date columns is via the Format setting:

columns.Bound(o => o.OrderDate).Format("{0:dd/MM/yyyy}");

You said that you are binding each column manually - could you please explain what this means? How are you applying the formatting in this case?

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Rickard
Top achievements
Rank 1
answered on 02 Nov 2011, 08:32 AM
By binding them manually, i mean i am writing out the columns instead of letting the grid autogenerate them. And in that case, i am formatting the date just like your example.

My question is, perhaps more clearly, is there a way to make autogenerated datetime columns come out in a specified format?

Thanks.
0
Atanas Korchev
Telerik team
answered on 02 Nov 2011, 08:46 AM
Hi Rickard,

Yes this is possible:

<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
                {  
                    columns.AutoGenerate(column =>
                        {                            
                            if (column.Member == "CustomerID")
                                column.Format = "{0:dd/MM/yyyy}";
                        })
;                        
                })
 %>

Kind regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Rickard
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Rickard
Top achievements
Rank 1
Share this question
or