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

Serverside grouping and paged results

1 Answer 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Holger
Top achievements
Rank 1
Holger asked on 06 Aug 2015, 07:35 AM

Hi,

i am asking if it is technically possible to use server side paging, sorting together with grouping using the kendo grid extension methods. I successfully implemented a repository that is executing a DataSourceRequest on an queryable sequence.

private PagedListResult<T> BuildResult(SearchQuery<T> searchQuery, IQueryable<T> sequence)
{
    var resultCount = sequence.Count();
 
    // Filter
    sequence = (IQueryable<TEntity>)sequence.Where(this.FilterDescriptors);
      
    var result = (searchQuery.Take > 0)
                     ? (sequence.Skip(searchQuery.Skip).Take(searchQuery.Take).ToList())
                     : (sequence.ToList());
 
    var hasNext = (searchQuery.Skip > 0 || searchQuery.Take > 0) &&
                  (searchQuery.Skip + searchQuery.Take < resultCount);
 
    return new PagedListResult<T>
           {
               Entities = result,
               HasNext = hasNext,
               HasPrevious = (searchQuery.Skip > 0),
               Count = resultCount
           };
}

 I tried to ​add grouping as well, but i cannot find a way how to handle it. There is an extension method that looks pretty: 

public override IQueryable<TEntity> ApplyGroups(IQueryable<TEntity> sequence)
{
    if (this.GroupDescriptors.Any())
    {
        var queryable = sequence.GroupBy(this.GroupDescriptors);
        return (IQueryable<TEntity>)queryable; // fails
    }
  
    return sequence;
}

But i am not able to cast it to IQueryable again in order to apply further filters and paging. The returned object is of type "Kendo.Mvc.Infrastructure.AggregateFunctionsGroup" and thats why I keep getting an invalidcastexception.

"System.Data.Entity.Infrastructure.DbQuery`1[Kendo.Mvc.Infrastructure.AggregateFunctionsGroup]" cannot be converted to type "System.Linq.IQueryable`1[MyEntity]" 

The internal query is looking as expected. Is there a way to cast it or what i am doing wrong? If not, how do you have to use this extension method in this custom binding scenario that must return a PagedListResult?

Many thanks in advcance, 

Holger

 

 

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 07 Aug 2015, 12:42 PM

Hello Holger,

Please refer to the attached project in the following forum thread reply that demonstrates how to bypass the built-in data processing and to handle operations by yourself. 

Regards,
Boyan Dimitrov
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
Holger
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or