javascriptangularjsui-grid

How to get all total for all rows across all pages in a UI-GRID


I am trying to display the total sum for a column in my UI-GRID. the problem is that I display 10 rows per page and the ui-grid footer only calculates the total sum for the the rows per page. How do I enable the ui-grid to calculate the total for all the rows in the UI-GRID

I have a created a plunker example to show my issue: http://next.plnkr.co/edit/Gjpt8tw4JpDzl1lG?preview


Solution

  • You can create a custom sum function and pass it in as the aggregationType in your grid options columnDefs.

    For example here is a function for the over all sum for address street numbers:

    var addOverAllTotalAddress = function() {
      var sum = 0;
       $scope.gridOptions.data.forEach(function(item){
        sum = sum + item.address.street;
      });
      return sum;
    };
    

    Here is a working plunker: http://next.plnkr.co/edit/ITkXFmIdD2ZJh1dS?preview