问题
My understanding is that Kendo does not support custom aggregates but you can call a function in the footerTemplate. That function then can provide calculations on the data and can even reference kendo defined aggregates. So, for example,
footerTemplate: "<div><b>Range</b> #= computeRange()#</div>"
If this is correct, how would you write the function computeRange? It would use max-min aggregates.
Also, how would you write a computeMedian function?
Thanks in advance for your help.
回答1:
function computeRange(){
var bal = 0;
var ds = $("#itemcode_grid").data("kendoGrid").dataSource;
var aggregates = ds.aggregates();
if(aggregates.total_balance)
bal = aggregates.total_balance.sum;
else
bal = 0;
return kendo.toString(bal,'n2');
}
回答2:
I've implemented a solution which my help you to use custom aggregate function using groupFooterTemplate.
Link here
function myAggregate(data){
// Data here is a list of data by group (brilliant right! :-) )
// Do anything here and return result string
}
var grid = $('#grid').kendoGrid({
...
columns: [
{ field: '', title: '', groupFooterTemplate: myAggregate
]
...
});
<!DOCTYPE html>
<html>
<head>
<!-- YOUR CSS HERE -->
</head>
<body>
...
<div id="#grid"></div>
...
<script><!-- jQuery here --></script>
<script><!-- kendo.all.min.js here --></script>
<script src="kendo.aggregate.helper.js"></script>
</body>
</html>
http://christfriedbalizou.github.io/kendo-grid-custom-aggregate-function-hack/
来源:https://stackoverflow.com/questions/13408302/kendo-grid-custom-aggregate-in-footertemplate