0
votes

I've set up a smart-table with pagination and search and I wish to display a sum of a column for all active rows. This means the entire data set by default and the filtered data set when a search is active. The smart-table documentation doesn't say much, so I've tried setting up a watch on my grid data variable. However, what this does is sum up only the rows on the current page, ignoring other pages. Can someone point me to where smart-table holds the current filtered data set and if there's a better way to watch for a search event? Thanks.

    $scope.$watch('gridData', function() {
        $scope.totalSum = 0;

        angular.forEach($scope.gridData, function(row) {
            $scope.totalSum += row.numericColumn;
        });
    });
1
looks like the user population of smart-table isn't quite scaling yet. i shall hop off to seek another library that does this then.ystan-

1 Answers

2
votes

This has been implemented lately, you can access the filtered collection for display purpose or logic purpose (like csv export) through the main controller method getFilteredCollection. An example of a directive to display the number of records which match a search

.directive('stSummary', function () {
    return {
      restrict: 'E',
      require: '^stTable',
      template: '<div>records:{{size}}</div>',
      scope: {},
      link: function (scope, element, attr, ctrl) {
        scope.$watch(ctrl.getFilteredCollection, function  (val) {
        scope.size = (val || []).length;
      })
     }
    }
})