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

Group date descending

1 Answer 209 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ExactBid
Top achievements
Rank 1
ExactBid asked on 23 Oct 2017, 05:13 PM

I am creating a Kendo grid with a datetime column. I want to group the date column so that it is descending. The latest date is on top and the earliest on the bottom. I have come across this line of code

groups => groups.AddDescending(true)

 

But it says that there is no definition for AddDescending. How do I change the grouping? Here is how my grid is defined.

@(Html.Kendo().Grid<LogModel>()
            .Name("Log")
            .Columns(columns =>
            {
                columns.Bound(m => m.dateTimeChangeDate)
                    .Title("Date and Time")
                    .ClientTemplate("#= ChangeDate#")
                    .ClientGroupHeaderTemplate("#= formatUtcDateToLocal(value,  'MM/DD/YYYY')#")
                    .Width("12%");
                columns.Bound(m => m.Component)
                    .Title("Component")
                    .Width("8%")
                    .Filterable(filterable => filterable
                        .UI("componentFilter")
                        .Extra(false)
                        .Operators(operators => operators
                            .ForString(str => str.Clear()
                            .Contains("Contains")
                         ))
                );
                columns.Bound(m => m.Action)
                    .Title("Action")
                    .Width("15%")
                    .Filterable(filterable => filterable
                        .UI("actionFilter")
                        .Extra(false)
                        .Operators(operators => operators
                            .ForString(str => str.Clear()
                            .Contains("Contains")
                        ))
                     );
                columns.Bound(m => m.Changer)
                    .Title("Changer")
                    .Width("10%");
                columns.Bound(m => m.Identifier)
                    .Title("On")
                    .Width("15%");
                columns.Bound(m => m.OldValue)
                    .Title("Old Value")
                    .Width("20%");
                columns.Bound(m => m.NewValue)
                    .Title("New Value")
                    .Width("20%");
            })
            .Filterable()
            .Selectable()
            .Sortable()
            .Groupable()
            .Resizable(resize => resize.Columns(true))
            .ToolBar(toolbar =>
            {
            toolbar.Template(
                @<text>
                    <a class="k-button k-button-icontext k-grid-excel" href="#"><span class="k-icon k-i-excel"></span>Export to Excel</a>
                    <span style='padding-left:35%;font-weight:bold;padding-top:7px'>@ViewBag.ProjectNumber</span>
                    <span style='float:right;font-weight:bold;padding-top:7px'>Total: <span id="change-log-record-count">@ViewBag.ChangeLogRecordAmount</span> records</span>
 
                </text>
                );
            })
            .Excel(excel => excel.AllPages(true).FileName(@ViewBag.ChangeLogType + " Change Log " + @ViewBag.ProjectNumber + ".xlsx").Filterable(true))
            .DataSource(dataSource => dataSource
                 .Ajax()
                 .Model(model =>
                 {
                     model.Id(p => p.Id);
                 })
                 .Read(read => read.Action("FetchChangeLogData", "ChangeLog")
                 .Data("buildParam"))
           )
           .Events(e => e.FilterMenuInit("resizeFilter")
                         .ExcelExport("modifyFormatForExcel")
                         .DataBound("preselectCustomFilter"))
           .ClientDetailTemplateId("change-log-details-template")
    )

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 25 Oct 2017, 11:21 AM
Hello,

Thank you for the provided code.

The group should be added inside the data source definitions:

.DataSource(dataSource => dataSource
      .Ajax()
      .Model(model =>
      {
          model.Id(p => p.Id);
      })
       .Group(groups => groups.Add(p => p.TheNameOfTheDateField))
      .Read(read => read.Action("FetchChangeLogData", "ChangeLog")
      .Data("buildParam"))
)

I hope this is helpful.

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
ExactBid
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or