1

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.

Pitamber Tiwari
  • 536
  • 1
  • 6
  • 19

1 Answers1

1

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);
}
Daniel
  • 5,602
  • 4
  • 33
  • 36
  • Yup, this one works without custom binding. As I said, I need to use Custom Binding instead of Server using .EnableCustomBinding(true) and .BindTo(Model). When I enable them, the group does not work. I guess the grouping must be done in the Controllers, but I am not sure how to. – Pitamber Tiwari Jun 28 '12 at 13:35
  • Yes, you are right with custom binding the grouping is done in the controller. I changed my answer to show how I think this should be done. – Daniel Jun 28 '12 at 14:31
  • I have the grouping done on the server side. I need to show them on the client side. I just don't know how to show them, i.e.show the groupby column. I want my group name and value to be shown like this example here (http://demos.kendoui.com/web/grid/aggregates.html). – Pitamber Tiwari Jun 28 '12 at 22:09