Kendo - Grid - Custom Aggregate in FooterTemplate

2019-08-18 20:30发布

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.

2条回答
太酷不给撩
2楼-- · 2019-08-18 20:44
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');
}
查看更多
做个烂人
3楼-- · 2019-08-18 20:48

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/

查看更多
登录 后发表回答