0
votes

New to Telerik Mvc, so I'm hoping I'm missing the obvious here. I am using version 2011.3.1115.340 of Telerik Mvc. The grid is being databound via ajax calls to controller actions and then the columns are hooked in to public properties. About as boilerplate as you can get.

Html.Telerik().Grid<ProductResult>()
    .Name("Grid")
    .DataBinding(databinding => databinding.Ajax()
        .Select("GetProductInfo", "Product"))
    .DataKeys(keys => keys.Add(a => a.ProductId))
    .Columns(columns => {
        columns.Bound(a => a.CreateDate).Width(30);
        columns.Bound(a => a.Sales).Width(30);
    columns.Bound(a => a.Service).Width(30);
    columns.Bound(a => a.Training).Width(30);
    columns.Bound(a => a.ModifiedDate).Width(30);
    })
    .Pageable(p => p.PageSize(30))
    .Sortable()
    .Filterable()
    .Groupable()

All filtering, aside from date values, works fine. The bound class is ultimately delivered from a wcf service where the datetime values are formatted in the data contract

[DataMember]
[DisplayName("Last Modified Date")]
[DisplayFormat(DataFormatString = "{0:d}")]
public virtual DateTime ModifiedDate { get; set; }

When I use the built-in grid filter (dropdown) and enter a date value that I know exists in the datasource and can see in the grid, I get no results - an empty grid. I've read posts that seem to indicate that this should work like a charm, but obviously not in my case. Any idea what I'm doing wrong here?

2

2 Answers

0
votes
columns.Bound(a => a.ModifiedDate).Format("{0:d}").Width(30);
0
votes

I'm guessing your Date field "Modified Date" is a DateTime field. This is caused because the datepicker filter in KendoUI can't match up the time portion of your DateTime values. Since nothing exactly matches the values in your database, it returns nothing.

I recently battled this as well and my best solution was to cast the DateTime fields in SQL to a Date when I was selecting the fields with my SPROC. Yours would look something like this, assuming you are using SQL.

SELECT CAST(ModifiedDate AS date) AS ModifiedDate FROM YourTable

That fixed my problem of the filter as it was now returning the rows I wanted.

This exposed another problem for me as now my date values were all getting offset by minus six hours because we were hosting our site on Azure. To remedy that problem I followed exactly this from the Kendo team:

Kendo - Using UTC time on both client and server sides