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

Date column type doesn't work when data source is a datatable

3 Answers 282 Views
Grid
This is a migrated thread and some comments may be shown as answers.
N
Top achievements
Rank 1
N asked on 24 Sep 2012, 01:06 PM
Hi there,

I have a kendo grid which binds into  a datatable (it has to bind into a datatable as I do not know which columns i am expecting)
It seems like when binding a grid to a datatable, date columns are not being recognized as dates, and rendered as strings. So no filtering, sorting or formatting, and the date is being displayed in the json string format: /Date(1348489271318)/

The mark up is as follows:
    @{ Html.Kendo().Grid(Model.GridModel)
        .Name("Grid")
        .Columns(columns =>
        {
            foreach (System.Data.DataColumn column in Model.GridModel.Columns)
            {              
                var c = columns.Bound(column.DataType, column.ColumnName).Title(column.Caption);
             
                 if (column.ColumnName == "DateAdded")
                {                   
                    c.Format("{0:dd/MM/yyyy hh:mm}");
                 }
            }
        })

Once I change the datasource into a class model, then everything works fine, the dates are rendered as dates with the correct format, filtering and sorting.

Any ideas why column of datatype date is getting rendered as a string?
Thanks
N

3 Answers, 1 is accepted

Sort by
0
Accepted
Rihards
Top achievements
Rank 1
answered on 25 Sep 2012, 04:26 PM
I had similar problem. I got it working by adding filled ModelFieldDescriptor variable for each column to DataSource.Schema.Model.Fields collection. In my experience Grid does not use MemberType specified at Bound column any more, but instead relays on information in DataSource.Schema.Model.
.
0
N
Top achievements
Rank 1
answered on 26 Sep 2012, 09:44 AM
Great, thank you!
0
Trevor
Top achievements
Rank 1
answered on 28 May 2013, 10:07 PM
I've got a similar issue as well and I'm having trouble implementing your suggestion.

Would it be possible to include a small sample?

Thanks,

Greg
Tags
Grid
Asked by
N
Top achievements
Rank 1
Answers by
Rihards
Top achievements
Rank 1
N
Top achievements
Rank 1
Trevor
Top achievements
Rank 1
Share this question
or