Kendo - Grid - Custom Aggregate in FooterTemplate

送分小仙女□ 提交于 2019-12-11 14:26:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!