Pitamber Tiwari
Pitamber Tiwari

Reputation: 536

Implement groupby expression on the Kendo UI Grid using MVC helper extension

I am using Kendo UI Grid to display my results. I am using the asp.net mvc helper extension method to create the Grid with the Custom Binding to implement the paging as explained in the documentation (http://www.kendoui.com/documentation/asp-net-mvc/helpers/grid/custom-binding.aspx). My result data can be grouped into 5 different groups (Group1Id, Group2Id...). I need to group the result using these group Ids. Can anyone tell me how to implement the groupBy. In telerik grid (for the webforms) I used GridGroupByExpression. I would like something that is similar to this behavior. There is

.Group(groups =>
    {
       groups.Add(p => p.Group1Id);
        groups.Add(p => p.Group2Id);
    }

it did not work for the custom binding. However, it works for the server binding. I haven't tried the Ajax binding yet.

Upvotes: 1

Views: 3025

Answers (1)

Daniel
Daniel

Reputation: 5742

Grouping is done similar to how sorting is done for custom binding.

public ActionResult Index([DataSourceRequest]DataSourceRequest request)
{
  IQueryable<Order> orders = new NorthwindDataContext().Orders;

  //Apply grouping
  foreach (GroupDescriptor groupDescriptor in request.Groups)
  {
    switch (groupDescriptor.Member)
    {
      case "Group1Id":
        orders.GroupBy(s => s.Group1Id);
        break;
      case "Group2Id":
        orders.GroupBy(s => s.Group2Id);
        break;
    }
  }

  return View(orders);
}

Upvotes: 1

Related Questions