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

Grid with ServerAggregates Example

7 Answers 606 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 2
Iron
Veteran
Keith asked on 26 Aug 2015, 05:10 PM
Do you have an example of using the Kendo Grid control for javascript that sets the options to serverAggregates = true?  I have been trying to make this work and sadly only can get the client aggregation working.  I have read numerous configuration settings and other forums that make suggestions.  An example would be more affective showing both the data source options and the grid options working together.

7 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 28 Aug 2015, 11:19 AM

Hello Keith,

Please find below the required information in order to enable the server aggregates. 

schema.aggreates defines the field in the server response which contains the calculated aggregates.

aggregate option defines what aggregate function must be calculated. Those functions will be send to server when read request is issued in order to instruct the server handler what data is required.

In order to show aggregates from DataSource inside Grid footer you must define footerTemplate for the columns.

Also I attached a sample project to illustrate the described approach. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeffrey
Top achievements
Rank 1
answered on 29 Oct 2015, 04:25 PM

I was looking at this example and it doesn't quite work for me.  We are using the virtualization option on the grid and also doing custom paging.  I am not using the ToDatasourceResult functions to return from the controller.

var result = new DataSourceResult

{
Data = data,
Total = pager.TotalRows
};

There is a property on the DataSourceResult that is called AggregateResults but man, I can't figure out how to set that.  Can't seem to find any examples of this property being set and how to set it.  Are there any examples of this somewhere?

Here is my entire controller method so you can see in what context I am using this.  Appreciate any assistance you can provide.

public ActionResult SearchAccounts([DataSourceRequest] DataSourceRequest request, HouseholdAccountSearchCriteria searchCriteria)
{
    var pager = TrustHelper.GetPagerFromKendoRequest(request);
    var orderBy = TrustHelper.GetSortFromKendoRequest(request);
 
    var data = _householdService.SearchAccounts(searchCriteria, orderBy, null);
 
    var result = new DataSourceResult
    {
        Data = data,
        Total = pager.TotalRows,
        AggregateResults = ??
    };
 
    return Json(result);
}

0
Boyan Dimitrov
Telerik team
answered on 02 Nov 2015, 01:39 PM
Hello Jeffrey,

In case of creating the DataSourceResult without using the ToDatasourceResult method all calculations should be done manually. 

I am afraid that we do not have any sample that shows the AggregateResults calculations. My suggestion is to use the project from my last post and inspect the DataSourceResult object after calling the ToDatasourceResult method. This will help you to determine what data and format should be used for the AggregateResults field. 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jeffrey
Top achievements
Rank 1
answered on 04 Nov 2015, 09:01 PM

Well, that sounds easy enough lol.  You can't create what that result looks like because most all the properties on the AggregateResult class ​are read only.  I need to set the Member that the aggregate is for and I can't figure out how to do that.  The constructor takes a value and a function, but no where I can tell it what member.  Any help would be appreciated.

I guess for now I am just going to put some script on the client to set the footer values.  Would be nice to know how to do this properly on the server.

 Thanks

 

var aggregateResults = new List<AggregateResult>();
var agResult = new AggregateResult(123, new SumFunction());
agResult.Member = ??
aggregateResults.Add(agResult);

0
Boyan Dimitrov
Telerik team
answered on 06 Nov 2015, 03:12 PM

Hello Jeffrey,

 

 

Indeed the Member property is read-only, because it should be set using the AggregateFunction. The SourceField is the name of the field, which value is used as the argument of the aggregate function. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Phil
Top achievements
Rank 1
answered on 26 Feb 2020, 04:28 PM

Hi Jeffrey,

Did you get a variation of this working?

 

var aggregateResults = new List<AggregateResult>();
var agResult = new AggregateResult(123, new SumFunction());
agResult.Member = ??
aggregateResults.Add(agResult);

 

Thanks

0
Angel Petrov
Telerik team
answered on 28 Feb 2020, 03:40 PM

Hello,

Another option to the provided one is to create different classes that do not have read-only members and do the calculations and etc manually. As long as the JSON from the server is the same as the one which we return the grid should populate.

Regards,
Angel Petrov
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Keith
Top achievements
Rank 2
Iron
Veteran
Answers by
Boyan Dimitrov
Telerik team
Jeffrey
Top achievements
Rank 1
Phil
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or