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

Grid in Ajax mode reads date time as string

2 Answers 263 Views
Grid
This is a migrated thread and some comments may be shown as answers.
M Kamil SAGIROGLU
Top achievements
Rank 1
M Kamil SAGIROGLU asked on 05 May 2013, 03:29 PM
Hi,

When I set DataSource to a grid datetime values are converted to string as /Date(1362607200000)/,
removing DataSource and command column works but I need command values so I should set DataSource for functions.

Works
Html.Kendo().Grid(Model)
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.CaptureRequest.Title).HtmlAttributes(new { style = "cursor:pointer" }).Title(ContentProvider.Resources.Names.Name);
        columns.Bound(p => p.CaptureRequest.StartDate).Format("{0:dd.MM.yyyy}").Title(ContentProvider.Resources.Names.StartDate);
        columns.Bound(p => p.CaptureRequest.EndDate).Format("{0:dd.MM.yyyy}").Title(ContentProvider.Resources.Names.EndDate);
    })
Sample output
Start Time            End Time
230.01.2013                08.02.2013

Doesn't Work
Html.Kendo().Grid(Model)
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.CaptureRequest.Title).HtmlAttributes(new { style = "cursor:pointer" }).Title(ContentProvider.Resources.Names.Name);
        columns.Bound(p => p.CaptureRequest.StartDate).Format("{0:dd.MM.yyyy}").Title(ContentProvider.Resources.Names.StartDate);
        columns.Bound(p => p.CaptureRequest.EndDate).Format("{0:dd.MM.yyyy}").Title(ContentProvider.Resources.Names.EndDate);
        columns.Command(command => command.Destroy()).Width(90);
    })
.DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events =>
        {
            events.Error("onGridError");
            events.RequestEnd("onGridRequestEnd");
        })
        .Model(model =>
        {
            model.Id(p => p.CaptureRequest.ID);
        })
        .Read(read => read.Action("RequestGridSource/" + @ViewBag.id, "TstvOperation"))
        .Destroy(update => update.Action("DeleteActiveCaptureRequest", "TstvOperation"))
    )
Sample output
Start Time                        End Time
/Date(1359038400000)/          /Date(1359044400000)/

What should be done to keep datetime values with formatting?

Thanks

2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 07 May 2013, 11:55 AM
Hi,

Basically this behavior is expected as currently the Grid is bind to complex model which is not supported out-of-the-box. I would suggest to flatter your model or use column template in which to manually parse the date using kendo.parseDate method:

columns.Bound(p => p.CaptureRequest.StartDate).ClientTemplate("#= kendo.format('{0:dd.MM.yyyy}', kendo.parseDate(CaptureRequest.StartDate)) #");

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Evan
Top achievements
Rank 1
answered on 24 Jun 2013, 08:20 PM
Although this may work, I believe the better solution is to specify the data types in the datasource config.  For example:
.DataSource(dataSource => dataSource
        .Ajax()
        .Model(model =>
            {
                foreach (System.Data.DataColumn column in Model.Columns)
                {
                    model.Field(column.ColumnName, column.DataType);
                }                
            })
        .Read(read => read.Action("Read", "Home"))

This solution is taken from the example posted by Petur in this Other Thread.
Tags
Grid
Asked by
M Kamil SAGIROGLU
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Evan
Top achievements
Rank 1
Share this question
or