Kendo MVC Grid Not Grouping When Using ClientGroupHeaderTemplate

时间:2015-07-28 16:20:26

标签: asp.net-mvc kendo-grid kendo-asp.net-mvc

I have the following code to create my Kendo Grid but as you can see, it isn't grouping by CreatedDate correctly. It works when I don't use ClientGroupHeaderTemplate().

The question is, how can I use .Group() when using ClientGroupHeaderTemplate()?

enter image description here

@(Html.Kendo().Grid<Models.MCMessageCenter>()
    .Name("myMessagesGrid")
    .Columns(columns =>
    {
        columns.Bound(c => c.Id);
        columns.Bound(c => c.MessageTitle);
        columns.Bound(c => c.CreatedDate)
            .ClientTemplate("#= kendo.toString(kendo.parseDate(CreatedDate), 'yyyy-MM-dd') #")
            .ClientGroupHeaderTemplate("#= kendo.toString(kendo.parseDate(value), 'yyyy-MM-dd') #");
    })
    .Scrollable()
    .Groupable()
    .Sortable()
    .Pageable(p => p
        .Refresh(true)
        .PageSizes(new int[] { 20, 50, 100 })
        .ButtonCount(5)
    )
    .DataSource(ds => ds
        .Ajax()
        .Group(g => g.Add(c => c.CreatedDate))
        .Sort(s => s.Add(c => c.CreatedDate).Descending())
        .Read(r => r.Action("MyMessagesRead", "Message"))
    )
)

I believe it's not working because the grouping functionality takes place on the server. However, I don't want to convert the IQueryable to an IEnumerable since I the dataset could be large. I would need a way of modifying the date before it gets sent to the view.

Update: Overriding the ToDataSourceResult method results in the following error:

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试通过在schema_migrations定义中添加以下行来向您的数据源添加模型定义:

DataSource()

完整示例:

.Model(mdl => mdl.Field(x => x.CreatedDate.Date))