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

Grid Template Column - Applying Date format

3 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gautam
Top achievements
Rank 1
gautam asked on 14 Feb 2013, 06:37 PM
I have a template column in the grid as below,

columns.Template(
            @<text>
            @item.GrantStartDate-@item.GrantEndDate
            </text>
            ).Title("START-END DATE");


Both @item.GrantStartDate and @item.GrantEndDate are nullable dates.

How can I apply 'yyyy-MM-dd' format to these dates 
Thanks

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 18 Feb 2013, 09:56 AM
Hi Gautam,

You could apply a custom date format in a server template by specifying it in the ToString() method.
E.g.
.Template(@<text>@item.GrantStartDate.Value.ToString("yyyy-MM-dd")-@item.GrantEndDate.Value.ToString("yyyy-MM-dd")</text>);

 

Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
gautam
Top achievements
Rank 1
answered on 18 Feb 2013, 02:08 PM
Hi Dimiter,
Thanks. I had already tried that but this fails if the date is null. Is it possible to check for null/HasValue within the <text> block, as below

@item.GrantStartDate.HasValue? item.GrantStartDate.Value.ToString("yyyy-MM-dd"): string.Empty()

Thanks,
Gautam
0
Accepted
Dimiter Madjarov
Telerik team
answered on 18 Feb 2013, 03:11 PM
Hi again Gautam,

Yes, you could easily include the check about the NULL value.
E.g.

.Template(@<text>
@(item.GrantStartDate.HasValue ? item.GrantStartDate.Value.ToString("yyyy-MM-dd") : String.Empty) -
@(item.GrantEndDate.HasValue ? item.GrantEndDate.Value.ToString("yyyy-MM-dd") : String.Empty)
</text>);

Wish you a great day!

Kind regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
gautam
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
gautam
Top achievements
Rank 1
Share this question
or