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

Grid Datasource is DateTime, but handled as a String

4 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 10 Nov 2017, 08:33 AM

 

This is (in short) my Grid code:

@(Html.Kendo().Grid<Model>()
.Name("Grid")
.Columns(columns =>
{
 
    columns.Bound(p => p.From).Format("{0:dd.MM.yyyy}").Width(150).Filterable(f => {
        f.UI("DateTimeFilter");
        f.Cell(cell => cell.ShowOperators(false));
    });
})

.Filterable(filterable => filterable
.Extra(false)
      .Operators(operators => operators
          .ForString(str => str.Clear()
              .Contains("Contains")
          ).ForDate( date => date.Clear()
         .IsGreaterThan("After")
         .IsLessThan("Before")
          )
          .ForNumber(number => number.Clear()
        .IsGreaterThan("Higher than")
        .IsLessThan("Lower than")
          ))

      )
    .Sortable()
    .Scrollable()
    .DataSource(dataSource => dataSource

        .Ajax()
        .ServerOperation(false)
        .Read(read => //get some data)
        
     )
        )

 

The fact is that p.From is treated as a String (so he gets the filter of a string = .ForString(...)). 

How is this possible? the format is also not aplied, but that works when i do this: .ClientTemplate("#= From? kendo.toString(kendo.parseDate(From), 'dd/MM/yyyy') : '' #")

 

Anybody expirienced this problmen yet?

4 Answers, 1 is accepted

Sort by
0
Steven
Top achievements
Rank 1
answered on 10 Nov 2017, 09:07 AM

Fixed it by creating a custom datasource and specify the model again (no idea why):

...

 .Schema(s => s
         .Data("Data")
           .Total("Total")
           .Errors("Errors")
           .Parse(@<text>function (data) {
        
        return data;
        }</text>)
            .Model(model =>
            {
                model.Field(m => m.From);
            })
    )
    .Transport(t =>
    {

...

 

Only the Filtering does not work now :-)

0
Stefan
Telerik team
answered on 15 Nov 2017, 07:55 AM
Hello, Steven,

Thank you for the provided code and providing the additional details after modifying it.

In general, this issue should only occur if the type fo the field is not set as DateTime in the Model.

Another issue could be that the custom UI "DateTimeFilter" used for filtering has a different format.

Could you please share the Model and one record of the Data which is passed to the Grid, so I can test if there are any issues when parsing the values.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Steven
Top achievements
Rank 1
answered on 15 Nov 2017, 07:59 AM

I did not need to create a custom datasource, only attach the model.

The model looked like this: 

      [Display(Name = "From")]
        public DateTime From { get; set; }

0
Stefan
Telerik team
answered on 17 Nov 2017, 12:18 PM
Hello, Steven,

Based on the provided information it seems that the issue is resolved after attaching the model.

If my assumption is not correct, please provide the filter UI and the data, so we can investigate.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Steven
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or