0
votes

My DateTime column gets displayed as "/Date(1520608915000)/" within my Kendo grid. Can you please advise how it should be fixed? I tried adding several Templates but the front end format of date remains numeric each time. Here is my code:

Column0 = Convert.ToDateTime("3/9/2018 4:21:55 PM"),

@(Html.Kendo().Grid<Project.Mvc.Models.GridViewModel>()
            .Name("GName")
            .Columns(columns =>
            {
                columns.Bound(c => c.Column0).Title("Date and Time").Width(100).Visible(true).Encoded(false).ClientTemplate(null);
                columns.Bound(c => c.Column1).Title("Name").Width(100).Visible(true).Encoded(false).ClientTemplate(null);
            })
            .AutoBind(false)
            .HtmlAttributes(new { style = "height:" + gridHeight + "px;width:" + gridWidth + "px;" })
            .Scrollable()
            .Selectable()
            .Sortable()         
            .ColumnMenu()
            .Resizable(resize => resize.Columns(false))
            .Pageable(pageable => pageable
                .Enabled(pageableEnabled)
                .Refresh(true)
                .PageSizes(true)
                .ButtonCount(7)
            )
            .Filterable(filterable => filterable
                .Extra(false)
                .Operators(operators => operators
                    .ForString(str => str.Clear()
                        .StartsWith(@Project.Mvc.Resources.StartsWith)
                        .Contains(@Project.Mvc.Resources.Contains)
                    ))
                )
                .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action(readAction, controller).Data(datasourceParameterAction))
                .Model(model => model.Id(c => c.Column0))
                )
                .Events(events => events
                .Change("GNameChange")
                .DataBound("GNameBound")
                )

     )

Below are things I tried (no success):

columns.Bound(c => c.Column0).Title("Date and Time").Width(100).Visible(true).Format("{0: M/d/yyyy h:mm:ss tt}").Encoded(false).ClientTemplate(PopupColumnTemplates[0]);

columns.Bound(c => c.Column0).Title("Date and Time").Width(100).Visible(true).Format("{0: M/d/yyyy h:mm:ss tt}").Encoded(false);

columns.Bound(c => c.Column0).Title("Date and Time").Width(150).Visible(true).Format("{0: M/d/yyyy h:mm:ss tt}");

columns.Bound(c => c.Column0).Title("Date and Time").Width(150).Visible(true).Format("{0: yyyy}");

columns.Bound(c => c.Column0).Title("Date and Time").Width(150).Visible(true).Format("{0: yyyy}").ClientTemplate("#= kendo.toString(Column0, \"yyyy\") #");
2
Column0 ("Date and Time"). Fix found, answer below. txTom S

2 Answers

1
votes

The following one is working

columns.Bound(c => c.Column0).Title("Date and Time").Format("{0: dd/MM/yyyy HH:mm}").Width(150);

You can refer Kendo Grid Automatically changing Timezone

0
votes

I found a working fix for my issue:

columns.Bound(c => c.Column0).Title("Date and Time").Width(100).Visible(true).ClientTemplate("#= kendo.toString(kendo.parseDate(Column0, 'M/d/yyyy h:mm:ss tt'), 'M/d/yyyy h:mm:ss tt') #");