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

Server side grouping by a composite class

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrii
Top achievements
Rank 1
Andrii asked on 15 Oct 2014, 09:56 AM
Hi,

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.

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 17 Oct 2014, 08:00 AM
Hello Andrii,

Basically, the DataSource will make a request that looks roughly like that: 
sort:
page:1
pageSize:20
group:ComplexID.cID-asc
filter:

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);


Regards,
Alexander Popov
Telerik
 

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.

 
Tags
Grid
Asked by
Andrii
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or