Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show date instead of DateTime in telerik Grid

i am using telerik grid in my Asp.Net MVC3 application and i want to bind a Date of format dd/mm/yyyy to one of the columns of the grid as shown below:

Html.Telerik().Grid<TestResults>()
    .Name("TestResultGrid")
    .DataKeys(keys => keys.Add(c => c.SourceProgramId))
    .Columns(columns =>
        {
            columns.Bound(c => c.OriginalSourceProgramId).Title("Original Case ID").Width("90").Visible(IsOriginalCaseIdVisible);
            columns.Bound(c => c.SourceProgramId).Title("Source Program ID").Width  ("90").Visible(!IsOriginalCaseIdVisible);
           columns.Bound(c => c.Name).Title("Name").Width("140");
            columns.Bound(c => c.Points).Title("Points").Width("50");
            columns.Bound(c => c.ProgramName).Title("Program").Width("80");
            columns.Bound(c => c.DOB).Title("Created Date").Width("80");
        })
    .DataBinding(dataBinding =>
            dataBinding.Ajax()
                .Select("_TestResutls", "Test"))
    .ClientEvents(events => events
    .OnDataBinding("Grid_onDataBinding")
    .OnDataBound("Grid_onDataBound")
    .OnRowDataBound("onRowDataBound")
    .OnRowSelect("onRowSelected"))
    .Pageable(paging => paging.PageSize(10))
    .NoRecordsTemplate("<b>No Records to display.<b>")
    .Sortable()
    .Selectable()
    .HtmlAttributes(new { @class = "grid_table" })
    .Footer(true)
    .Render();

The dataType of DOB is DateTime?. I want to display date of format dd/mm/yyyy. i could have converted it to ToString() to achieve this, But i have sorting on this column. When i sort by this column it is treating the values as string and not returning the expected results. This column is nullable and hence i cant use DOB.Date method also. Any help?

like image 336
TRR Avatar asked Apr 25 '12 09:04

TRR


1 Answers

You should be able to do columns.Bound(c => c.DOB).Format("{0:dd/MM/yyyy}").Title("Created Date").Width("80");

Hope that helps

like image 101
Chris Surfleet Avatar answered Nov 15 '22 03:11

Chris Surfleet