Group date descending

2 posts, 0 answers
  1. ExactBid
    ExactBid avatar
    8 posts
    Member since:
    Oct 2017

    Posted 23 Oct 2017 Link to this post

    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")
        )
  2. Stefan
    Admin
    Stefan avatar
    1842 posts

    Posted 25 Oct 2017 Link to this post

    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.
Back to Top