ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Footer with multiple entries

Open pragatir opened this issue 11 years ago • 4 comments

With the latest unstable version, can I have multiple entries for my Footer? Eg., I want my footer to have "Total" and "Average" for each column. So, Total and Average will be displayed under each column in the footer in separate rows.

pragatir avatar Feb 27 '15 10:02 pragatir

Define functions

Array.prototype.avg = function (e) {
    if (this.length == 0)return 0;
    var t = 0;
    for (var n = 0; n < this.length; n++) {
        t += this[n]["entity"][e] / this.length
    }
    return t
};

Array.prototype.total = function (e) {
    if (this.length == 0)return 0;
    var t = 0;
    for (var n = 0; n < this.length; n++) {
        t += this[n]["entity"][e]
    }
    return t
};

Inside the controller define function for aggregating average and total:

averageAndTotal = function (e, t) {

        var n = e.avg(t.field);
        var r = e.total(t.field, n);
        return [n, r]
    };

Create a template

var temp = '<div class="ui-grid-cell-contents" col-index="renderIndex"><div>avg: {{ col.getAggregationValue()[0] | number : 2}}<br>total: {{ col.getAggregationValue()[1] | number : 2}}</div></div>';

Set aggregationType to averageAndTotal and footerCellTemplate to temp in gridOptions for column that you want to have this footer.

Hope it will help. Good luck!

amilosmanli avatar Feb 27 '15 17:02 amilosmanli

Solution provided (not clear to me if that will work), but no response for 3 weeks. Assuming issue is resolved, closing.

PaulL1 avatar Mar 28 '15 22:03 PaulL1

It worked. Great solution! @cyberlake

sunz7 avatar Apr 07 '15 17:04 sunz7

great

conanjunn avatar Apr 21 '15 06:04 conanjunn