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

Grouping in Grid serverside

3 Answers 317 Views
Grid
This is a migrated thread and some comments may be shown as answers.
IT-Consol
Top achievements
Rank 1
IT-Consol asked on 22 May 2014, 06:25 AM
Hi there,

I got some problems with grouping in my grid and couldn't find a proper solution yet.
What I need is to be able to group my elements in the grid AND also do lazy loading (IQueryable, ToDataSourceResult,...). I already tried a couple of things, but I didn't come up with a solution.
If I have one property to group by, I do so on serverside like "queryable.GroupBy(x=> x.MessageCategory)" but then I run into this error:
"Invalid property or field - "MessageCategory" for type: IGrouping`2"

If I do "request.Groups.Clear()" afterwards, I do get a sqlexception, because I cannot select x columns but only group by one.

So is there any possibility to do a grouping serverside, with lazy loading?

When I configure my grid to ".ServerOperation(false)", grouping works fine, but then I do not have any paging(lazy loading) anymore.

Thank You!

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 May 2014, 07:36 AM
Hello,

If you wish to group the data then you should add the group to the Grid DataSource options:
Html.Kendo().Grid<MyModel>()     
    .DataSource(dataSource => dataSource
        .Ajax()
        .Group(groups => groups.Add(x => x.MessageCategory))


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
IT-Consol
Top achievements
Rank 1
answered on 27 May 2014, 07:23 AM
Hi,

thank you for your answer, but this solution does not work for me.
First of all de grid always does some grouping, which I don't like (user should do grouping). and the next problem I ran into is again the exception "Column 'core.MessageVariants_v.id_messageVariant' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause." - which is the problem I described above in my first post, that I can not group by 1 column, and select x columns...

Any other suggestions regarding server side grouping?

Thank You!

0
Daniel
Telerik team
answered on 29 May 2014, 07:19 AM
Hello again,

If you wish to perform the grouping with custom code then you should use custom binding and create a DataSourceResult instead of using the ToDataSourceResult method. The group should still be set to the DataSource in order for the grid and the dataSource to know that the data is grouped and to process the response correctly.
The reason for the described exception is that IEnumerable of the grid model type(or at least one with the same properties) should be used for the ToDataSourceResult method and by applying the grouping the data becomes IEnumerable of IGrouping.

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
IT-Consol
Top achievements
Rank 1
Answers by
Daniel
Telerik team
IT-Consol
Top achievements
Rank 1
Share this question
or