7 Answers, 1 is accepted
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
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);
}
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
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);
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
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
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