Server side grouping by a composite class

2 posts, 0 answers
  1. Andrii
    Andrii avatar
    1 posts
    Member since:
    Oct 2014

    Posted 15 Oct 2014 Link to this post


    I'm trying to use KendoGrid server-side logic for grouping grid data with the help of ToDataSourceResult extension.

    public class User
            public int UserID;
            public string UserName;
            public int UserType;
            public ComplexID complexID;

    public class ComplexID
           public string cID;
           public string Description;

    I have a list of users:

    var userLst = new List<User>{usr1, usr2, usr3};

    I'm trying to group the users to be displayed in the KendoGrid:

    var kendoData = userLst.AsQueryable().ToDataSourceResult(kendoRequest);

    If I group by UserType, everything works fine. My question is how can I group the data by complexID.cID? What should I specify in kendoRequest?

    Thank you.
  2. Alexander Popov
    Alexander Popov avatar
    1444 posts

    Posted 17 Oct 2014 Link to this post

    Hello Andrii,

    Basically, the DataSource will make a request that looks roughly like that: 

    The controller will capture this request and the DataSourceRequest ModelBinder will translate it into an object that could be passed to the ToDataSourceResult method. Alternatively, you could manually build that object. For example: 
    var kendoRequest = new DataSourceRequest()
        Filters = Kendo.Mvc.Infrastructure.FilterDescriptorFactory.Create(""),
        Sorts = GridDescriptorSerializer.Deserialize<SortDescriptor>(""),
        Groups = GridDescriptorSerializer.Deserialize<GroupDescriptor>("complexID.cID-asc"),
        Aggregates = GridDescriptorSerializer.Deserialize<AggregateDescriptor>(""),
        Page = 1,
        PageSize = 20,
    var kendoData = userLst.AsQueryable().ToDataSourceResult(kendoRequest);

    Alexander Popov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top