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

[Solved] MVC grid grouping header customization

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eric
Top achievements
Rank 1
Eric asked on 08 Jun 2012, 08:11 PM
I am using the latest MVC grid.  I am grouping by Date.  My group header shows both date and the time is always 12:00.  How can I customize the grouping header to show the date only - no time.

Here is my code:

@using Telerik.Web.Mvc.UI
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns => {
columns.Bound(c => c.TimeStamp).Format("{0:t}").Width(120);
columns.Bound(c => c.Operation).Width(180);
columns.Bound(c => c.Details);
columns.Bound(c => c.UserName).Width(130);
})
.Footer(false)
.Sortable()
.HtmlAttributes(new {
@class = "maxHeight"
})
.Scrollable(scrolling => scrolling.Height("auto"))
.Groupable(grouping => grouping.Groups(groups => {
groups.Add(c => c.TimeStamp.Date);
})
)
)

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 13 Jun 2012, 09:03 AM
Hi Eric,

By default the format used for the value in the group header is the one that is used for the column. If you need to show the value in a different format, you should define a GroupHeaderTemplate e.g.
columns.Bound(c => c.TimeStamp).Format("{0:t}")
    .GroupHeaderTemplate(@<text>@string.Format("{0:d}",item.Key)</text>).Width(120);

Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or