From 6424373efc9065b1f0bc948dee3f1dc61973b5f0 Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Thu, 27 Aug 2015 10:32:31 +0200 Subject: [PATCH 1/9] Added demo for new feature --- examples/demo35.html | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 examples/demo35.html diff --git a/examples/demo35.html b/examples/demo35.html new file mode 100644 index 00000000..ec38cc00 --- /dev/null +++ b/examples/demo35.html @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + +

Table with summary footer

+ +
+ + + + + + +
+ {{user.name}} + + {{user.age}} +
+ + + +
+ + + + From 95618da212f87ff5dbea4e198a746b74442515ad Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Thu, 27 Aug 2015 11:35:08 +0200 Subject: [PATCH 2/9] Added appending footer to table and tablesummary directive --- dist/ng-table.js | 75 +++++++++++++--------- examples/demo35.html | 16 ----- src/ng-table/footer.html | 1 + src/ng-table/summaryRow.html | 7 ++ src/scripts/ngTableController.js | 17 ++++- src/scripts/ngTableSummaryRow.directive.js | 27 ++++++++ src/scripts/ngTableSummaryRowController.js | 22 +++++++ 7 files changed, 117 insertions(+), 48 deletions(-) create mode 100644 src/ng-table/footer.html create mode 100644 src/ng-table/summaryRow.html create mode 100644 src/scripts/ngTableSummaryRow.directive.js create mode 100644 src/scripts/ngTableSummaryRowController.js diff --git a/dist/ng-table.js b/dist/ng-table.js index 9ea4e960..34fb459d 100644 --- a/dist/ng-table.js +++ b/dist/ng-table.js @@ -10,7 +10,7 @@ } }(window.angular || null, function(angular) { 'use strict'; - + /** * ngTable: Table + Angular JS * @@ -27,7 +27,7 @@ */ angular.module('ngTable', []); })(); - + /** * ngTable: Table + Angular JS * @@ -49,7 +49,7 @@ settings: {} }); })(); - + /** * ngTable: Table + Angular JS * @@ -147,7 +147,7 @@ } } })(); - + /** * ngTable: Table + Angular JS * @@ -235,7 +235,7 @@ } } })(); - + /** * ngTable: Table + Angular JS * @@ -345,7 +345,7 @@ } } })(); - + /** * ngTable: Table + Angular JS * @@ -382,7 +382,7 @@ } } })(); - + /** * ngTable: Table + Angular JS * @@ -460,7 +460,7 @@ }; }]); })(); - + /** * ngTable: Table + Angular JS * @@ -1080,7 +1080,7 @@ })(); - + /** * ngTable: Table + Angular JS * @@ -1162,6 +1162,7 @@ if (!$element.hasClass('ng-table')) { $scope.templates = { header: ($attrs.templateHeader ? $attrs.templateHeader : 'ng-table/header.html'), + footer: ($attrs.templateFooter ? $attrs.templateFooter : 'ng-table/footer.html'), pagination: ($attrs.templatePagination ? $attrs.templatePagination : 'ng-table/pager.html') }; $element.addClass('ng-table'); @@ -1178,6 +1179,17 @@ headerTemplate = angular.element(document.createElement('thead')).attr('ng-include', 'templates.header'); $element.prepend(headerTemplate); } + var footerTemplate = null; + var tfootFound = false; + angular.forEach($element.children(), function(e){ + if (e.tagName === 'TFOOT') { + theadFound = true; + } + }); + if (!tfootFound) { + footerTemplate = angular.element(document.createElement('tfoot')).attr('ng-include', 'templates.footer'); + $element.append(footerTemplate); + } var paginationTemplate = angular.element(document.createElement('div')).attr({ 'ng-table-pagination': 'params', 'template-url': 'templates.pagination' @@ -1186,6 +1198,9 @@ if (headerTemplate) { $compile(headerTemplate)($scope); } + if (footerTemplate) { + $compile(footerTemplate)($scope); + } $compile(paginationTemplate)($scope); } }; @@ -1268,8 +1283,6 @@ } }; - - function commonInit(){ ngTableEventsChannel.onAfterReloadData(bindDataToScope, $scope, isMyPublisher); ngTableEventsChannel.onPagesChanged(bindPagesToScope, $scope, isMyPublisher); @@ -1294,7 +1307,7 @@ commonInit(); }]); })(); - + /** * ngTable: Table + Angular JS * @@ -1392,7 +1405,7 @@ } ]); })(); - + /** * ngTable: Table + Angular JS * @@ -1465,7 +1478,7 @@ }; }]); })(); - + /** * ngTable: Table + Angular JS * @@ -1517,7 +1530,7 @@ ]); })(); - + /** * ngTable: Table + Angular JS * @@ -1557,7 +1570,7 @@ }; } })(); - + /** * ngTable: Table + Angular JS * @@ -1585,7 +1598,7 @@ return directive; } })(); - + /** * ngTable: Table + Angular JS * @@ -1624,7 +1637,7 @@ } } })(); - + /** * ngTable: Table + Angular JS * @@ -1652,7 +1665,7 @@ return directive; } })(); - + /** * ngTable: Table + Angular JS * @@ -1728,16 +1741,18 @@ } } })(); - -angular.module('ngTable').run(['$templateCache', function ($templateCache) { - $templateCache.put('ng-table/filterRow.html', '
'); - $templateCache.put('ng-table/filters/number.html', ' '); - $templateCache.put('ng-table/filters/select-multiple.html', ' '); - $templateCache.put('ng-table/filters/select.html', ' '); - $templateCache.put('ng-table/filters/text.html', ' '); - $templateCache.put('ng-table/header.html', ' '); - $templateCache.put('ng-table/pager.html', ' '); - $templateCache.put('ng-table/sorterRow.html', '
'); -}]); + +angular.module('ngTable').run(['$templateCache', function ($templateCache) { + $templateCache.put('ng-table/filterRow.html', '
'); + $templateCache.put('ng-table/filters/number.html', ' '); + $templateCache.put('ng-table/filters/select-multiple.html', ' '); + $templateCache.put('ng-table/filters/select.html', ' '); + $templateCache.put('ng-table/filters/text.html', ' '); + $templateCache.put('ng-table/footer.html', ' '); + $templateCache.put('ng-table/header.html', ' '); + $templateCache.put('ng-table/pager.html', ' '); + $templateCache.put('ng-table/sorterRow.html', '
'); + $templateCache.put('ng-table/summaryRow.html', ' {{params.summaryValues()[$column.summary(this)]}} '); +}]); return angular.module('ngTable'); })); diff --git a/examples/demo35.html b/examples/demo35.html index ec38cc00..446afff3 100644 --- a/examples/demo35.html +++ b/examples/demo35.html @@ -69,22 +69,6 @@

Table with summary footer

params.total(collection.length); -/* - var summaryFuncs = params.settings().summaries; - var summaryValues = {}; - angular.forEach(summaryFuncs, function(summaryFunc) { - var column = summaryFunc(); - if (column) { - summaryValues[column] = 0; - angular.forEach(collection, function(row){ - summaryValues[column] += row[column]; - }); - } - }); - - params.summaryValues(summaryValues); -*/ - $defer.resolve( collection.slice((params.page() - 1) * params.count(), params.page() * params.count())); diff --git a/src/ng-table/footer.html b/src/ng-table/footer.html new file mode 100644 index 00000000..2dacc89d --- /dev/null +++ b/src/ng-table/footer.html @@ -0,0 +1 @@ + diff --git a/src/ng-table/summaryRow.html b/src/ng-table/summaryRow.html new file mode 100644 index 00000000..1eb34576 --- /dev/null +++ b/src/ng-table/summaryRow.html @@ -0,0 +1,7 @@ + + + {{params.summaryValues()[$column.summary(this)]}} + + diff --git a/src/scripts/ngTableController.js b/src/scripts/ngTableController.js index 6655675e..48c801ac 100644 --- a/src/scripts/ngTableController.js +++ b/src/scripts/ngTableController.js @@ -79,6 +79,7 @@ if (!$element.hasClass('ng-table')) { $scope.templates = { header: ($attrs.templateHeader ? $attrs.templateHeader : 'ng-table/header.html'), + footer: ($attrs.templateFooter ? $attrs.templateFooter : 'ng-table/footer.html'), pagination: ($attrs.templatePagination ? $attrs.templatePagination : 'ng-table/pager.html') }; $element.addClass('ng-table'); @@ -95,6 +96,17 @@ headerTemplate = angular.element(document.createElement('thead')).attr('ng-include', 'templates.header'); $element.prepend(headerTemplate); } + var footerTemplate = null; + var tfootFound = false; + angular.forEach($element.children(), function(e){ + if (e.tagName === 'TFOOT') { + theadFound = true; + } + }); + if (!tfootFound) { + footerTemplate = angular.element(document.createElement('tfoot')).attr('ng-include', 'templates.footer'); + $element.append(footerTemplate); + } var paginationTemplate = angular.element(document.createElement('div')).attr({ 'ng-table-pagination': 'params', 'template-url': 'templates.pagination' @@ -103,6 +115,9 @@ if (headerTemplate) { $compile(headerTemplate)($scope); } + if (footerTemplate) { + $compile(footerTemplate)($scope); + } $compile(paginationTemplate)($scope); } }; @@ -185,8 +200,6 @@ } }; - - function commonInit(){ ngTableEventsChannel.onAfterReloadData(bindDataToScope, $scope, isMyPublisher); ngTableEventsChannel.onPagesChanged(bindPagesToScope, $scope, isMyPublisher); diff --git a/src/scripts/ngTableSummaryRow.directive.js b/src/scripts/ngTableSummaryRow.directive.js new file mode 100644 index 00000000..8a879528 --- /dev/null +++ b/src/scripts/ngTableSummaryRow.directive.js @@ -0,0 +1,27 @@ +/** + * ngTable: Table + Angular JS + * + * @author Szymon Drosdzol + * @url https://github.com/sprzedamsanki/ng-table + * @license New BSD License + */ + + (function(){ + 'use strict'; + + angular.module('ngTable') + .directive('ngTableSummaryRow', ngTableSummaryRow); + + ngTableSummaryRow.$inject = []; + + function ngTableSummaryRow(){ + var directive = { + restrict: 'E', + replace: true, + templateUrl: 'ng-table/summaryRow.html', + scope: true, + controller: 'ngTableSummaryRowController' + }; + return directive; + } + })(); diff --git a/src/scripts/ngTableSummaryRowController.js b/src/scripts/ngTableSummaryRowController.js new file mode 100644 index 00000000..11d0ca60 --- /dev/null +++ b/src/scripts/ngTableSummaryRowController.js @@ -0,0 +1,22 @@ +/** + * ngTable: Table + Angular JS + * + * @author Szymon Drosdzol + * @url https://github.com/sprzedamsanki/ng-table + * @license New BSD License + */ + +(function(){ + 'use strict'; + + angular.module('ngTable') + .controller('ngTableSummaryRowController', ngTableSummaryRowController); + + ngTableSummaryRowController.$inject = ['$scope']; + + function ngTableSummaryRowController($scope){ + $scope.params.settings().summaries = $scope.$columns.map(function($column){ + return $column.summary; + }); + } +})(); From dfa865eb413d2a244e0a80cd9050b94b5ce6c61f Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Thu, 27 Aug 2015 11:37:46 +0200 Subject: [PATCH 3/9] Added files for summary row directive to build --- Gruntfile.js | 2 ++ dist/ng-table.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/Gruntfile.js b/Gruntfile.js index 064edff6..ace2b0c2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -69,6 +69,8 @@ module.exports = function(grunt) { 'src/scripts/ngTableFilterRow.directive.js', 'src/scripts/ngTableSorterRowController.js', 'src/scripts/ngTableSorterRow.directive.js', + 'src/scripts/ngTableSummaryRow.directive.js', + 'src/scripts/ngTableSummaryRowController.js', 'src/scripts/ngTableSelectFilterDs.directive.js', './.temp/scripts/views.js', 'src/scripts/outro.js' diff --git a/dist/ng-table.js b/dist/ng-table.js index 34fb459d..823c4362 100644 --- a/dist/ng-table.js +++ b/dist/ng-table.js @@ -1666,6 +1666,57 @@ } })(); +/** + * ngTable: Table + Angular JS + * + * @author Szymon Drosdzol + * @url https://github.com/sprzedamsanki/ng-table + * @license New BSD License + */ + + (function(){ + 'use strict'; + + angular.module('ngTable') + .directive('ngTableSummaryRow', ngTableSummaryRow); + + ngTableSummaryRow.$inject = []; + + function ngTableSummaryRow(){ + var directive = { + restrict: 'E', + replace: true, + templateUrl: 'ng-table/summaryRow.html', + scope: true, + controller: 'ngTableSummaryRowController' + }; + return directive; + } + })(); + +/** + * ngTable: Table + Angular JS + * + * @author Szymon Drosdzol + * @url https://github.com/sprzedamsanki/ng-table + * @license New BSD License + */ + +(function(){ + 'use strict'; + + angular.module('ngTable') + .controller('ngTableSummaryRowController', ngTableSummaryRowController); + + ngTableSummaryRowController.$inject = ['$scope']; + + function ngTableSummaryRowController($scope){ + $scope.params.settings().summaries = $scope.$columns.map(function($column){ + return $column.summary; + }); + } +})(); + /** * ngTable: Table + Angular JS * From be8e0f7dcd4079c3bb83e7fcec45bc98a49f6d78 Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Thu, 27 Aug 2015 11:44:33 +0200 Subject: [PATCH 4/9] Corrected directice name in footer template --- src/ng-table/footer.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng-table/footer.html b/src/ng-table/footer.html index 2dacc89d..5a513f0d 100644 --- a/src/ng-table/footer.html +++ b/src/ng-table/footer.html @@ -1 +1 @@ - + From cb7a49d201310b9c7898bca8cd5a579f4bef36c7 Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Thu, 27 Aug 2015 12:57:55 +0200 Subject: [PATCH 5/9] Added summary to table's parsed attributes --- dist/ng-table.js | 20 +++++++++++++++++--- src/scripts/ngTable.directive.js | 1 + src/scripts/ngTableColumn.js | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/dist/ng-table.js b/dist/ng-table.js index 823c4362..16a6bda2 100644 --- a/dist/ng-table.js +++ b/dist/ng-table.js @@ -408,6 +408,7 @@ headerTemplateURL: function(){ return false; }, headerTitle: function(){ return ''; }, sortable: function(){ return false; }, + summary: function() { return false; }, show: function(){ return true; }, title: function(){ return ''; }, titleAlt: function(){ return ''; } @@ -611,6 +612,20 @@ }) : settings.total; }; + /** + * @ngdoc method + * @name NgTableParams#summaryVaules + * @description If parameter summaryVaules not set return current summary else set current summaryVaules + * + * @param {string} summaryVaules + * @returns {Object|Number} Current summaryVaules or `this` + */ + this.summaryValues = function(summaryValues) { + return angular.isDefined(summaryValues) ? this.settings({ + 'summaryValues': summaryValues + }) : settings.summaryValues; + } + /** * @ngdoc method * @name NgTableParams#count @@ -1078,8 +1093,6 @@ return NgTableParams; }]); })(); - - /** * ngTable: Table + Angular JS @@ -1386,6 +1399,7 @@ sortable: parsedAttribute('sortable'), 'class': parsedAttribute('header-class'), filter: parsedAttribute('filter'), + summary: parsedAttribute('summary'), headerTemplateURL: parsedAttribute('header'), filterData: parsedAttribute('filter-data'), show: (el.attr("ng-if") ? function (scope) { @@ -1799,7 +1813,7 @@ angular.module('ngTable').run(['$templateCache', function ($templateCache) { $templateCache.put('ng-table/filters/select-multiple.html', ' '); $templateCache.put('ng-table/filters/select.html', ' '); $templateCache.put('ng-table/filters/text.html', ' '); - $templateCache.put('ng-table/footer.html', ' '); + $templateCache.put('ng-table/footer.html', ' '); $templateCache.put('ng-table/header.html', ' '); $templateCache.put('ng-table/pager.html', ' '); $templateCache.put('ng-table/sorterRow.html', '
'); diff --git a/src/scripts/ngTable.directive.js b/src/scripts/ngTable.directive.js index b857ddb9..eb7cd878 100644 --- a/src/scripts/ngTable.directive.js +++ b/src/scripts/ngTable.directive.js @@ -76,6 +76,7 @@ sortable: parsedAttribute('sortable'), 'class': parsedAttribute('header-class'), filter: parsedAttribute('filter'), + summary: parsedAttribute('summary'), headerTemplateURL: parsedAttribute('header'), filterData: parsedAttribute('filter-data'), show: (el.attr("ng-if") ? function (scope) { diff --git a/src/scripts/ngTableColumn.js b/src/scripts/ngTableColumn.js index 1dd1b006..62f33669 100644 --- a/src/scripts/ngTableColumn.js +++ b/src/scripts/ngTableColumn.js @@ -23,6 +23,7 @@ headerTemplateURL: function(){ return false; }, headerTitle: function(){ return ''; }, sortable: function(){ return false; }, + summary: function() { return false; }, show: function(){ return true; }, title: function(){ return ''; }, titleAlt: function(){ return ''; } From b3098735335911afc9cde9d7bdf96ab5858dabb8 Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Thu, 27 Aug 2015 12:59:42 +0200 Subject: [PATCH 6/9] Added summaryValues to setttings to keep calculated summaries --- src/scripts/ngTableParams.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/scripts/ngTableParams.js b/src/scripts/ngTableParams.js index e66c609e..ac1dc66c 100644 --- a/src/scripts/ngTableParams.js +++ b/src/scripts/ngTableParams.js @@ -148,6 +148,20 @@ }) : settings.total; }; + /** + * @ngdoc method + * @name NgTableParams#summaryVaules + * @description If parameter summaryVaules not set return current summary else set current summaryVaules + * + * @param {string} summaryVaules + * @returns {Object|Number} Current summaryVaules or `this` + */ + this.summaryValues = function(summaryValues) { + return angular.isDefined(summaryValues) ? this.settings({ + 'summaryValues': summaryValues + }) : settings.summaryValues; + } + /** * @ngdoc method * @name NgTableParams#count @@ -615,5 +629,3 @@ return NgTableParams; }]); })(); - - From 942d536a78ac5e2811b689408f68c89b0b310757 Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Thu, 27 Aug 2015 13:01:04 +0200 Subject: [PATCH 7/9] Added calculating summaries in getData function --- examples/demo35.html | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/demo35.html b/examples/demo35.html index 446afff3..92b76672 100644 --- a/examples/demo35.html +++ b/examples/demo35.html @@ -56,8 +56,6 @@

Table with summary footer

{name: "Enos", age: 34}]; function filterSortAndSlice(collection, $defer, params) { - debugger; - collection = params.filter() ? $filter('filter')(collection, params.filter()) : @@ -69,6 +67,21 @@

Table with summary footer

params.total(collection.length); + var summaryValues = {}; + var summaryFuncs = params.settings().summaries; + angular.forEach(summaryFuncs, function(summaryFunc) { + summaryIndex = summaryFunc(); + + if (summaryIndex) { + summaryValues[summaryIndex] = 0; + debugger; + angular.forEach(collection, function(row){ + summaryValues[summaryIndex] += row[summaryIndex]; + }); + } + }); + params.summaryValues(summaryValues); + $defer.resolve( collection.slice((params.page() - 1) * params.count(), params.page() * params.count())); From 6d7ad36a1ce44b34caacd02f5216678204346b5e Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Mon, 31 Aug 2015 10:54:27 +0200 Subject: [PATCH 8/9] Added possibility to define summary cells' classes --- dist/ng-table.js | 4 +++- examples/demo35.html | 3 +-- src/ng-table/summaryRow.html | 3 ++- src/scripts/ngTable.directive.js | 1 + src/scripts/ngTableColumn.js | 1 + 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dist/ng-table.js b/dist/ng-table.js index 16a6bda2..e322d406 100644 --- a/dist/ng-table.js +++ b/dist/ng-table.js @@ -409,6 +409,7 @@ headerTitle: function(){ return ''; }, sortable: function(){ return false; }, summary: function() { return false; }, + summaryClass: function(){ return ''; }, show: function(){ return true; }, title: function(){ return ''; }, titleAlt: function(){ return ''; } @@ -1400,6 +1401,7 @@ 'class': parsedAttribute('header-class'), filter: parsedAttribute('filter'), summary: parsedAttribute('summary'), + summaryClass: parsedAttribute('summary-class'), headerTemplateURL: parsedAttribute('header'), filterData: parsedAttribute('filter-data'), show: (el.attr("ng-if") ? function (scope) { @@ -1817,7 +1819,7 @@ angular.module('ngTable').run(['$templateCache', function ($templateCache) { $templateCache.put('ng-table/header.html', ' '); $templateCache.put('ng-table/pager.html', ' '); $templateCache.put('ng-table/sorterRow.html', '
'); - $templateCache.put('ng-table/summaryRow.html', ' {{params.summaryValues()[$column.summary(this)]}} '); + $templateCache.put('ng-table/summaryRow.html', ' {{params.summaryValues()[$column.summary(this)]}} '); }]); return angular.module('ngTable'); })); diff --git a/examples/demo35.html b/examples/demo35.html index 92b76672..7bc7e64f 100644 --- a/examples/demo35.html +++ b/examples/demo35.html @@ -28,7 +28,7 @@

Table with summary footer

{{user.name}} + summary="'age'" summary-class="'test-class'"> {{user.age}} @@ -74,7 +74,6 @@

Table with summary footer

if (summaryIndex) { summaryValues[summaryIndex] = 0; - debugger; angular.forEach(collection, function(row){ summaryValues[summaryIndex] += row[summaryIndex]; }); diff --git a/src/ng-table/summaryRow.html b/src/ng-table/summaryRow.html index 1eb34576..a7aaa25c 100644 --- a/src/ng-table/summaryRow.html +++ b/src/ng-table/summaryRow.html @@ -1,7 +1,8 @@ + ng-if="$column.show(this)" + ng-class="$column.summaryClass()"> {{params.summaryValues()[$column.summary(this)]}} diff --git a/src/scripts/ngTable.directive.js b/src/scripts/ngTable.directive.js index eb7cd878..ac935bc2 100644 --- a/src/scripts/ngTable.directive.js +++ b/src/scripts/ngTable.directive.js @@ -77,6 +77,7 @@ 'class': parsedAttribute('header-class'), filter: parsedAttribute('filter'), summary: parsedAttribute('summary'), + summaryClass: parsedAttribute('summary-class'), headerTemplateURL: parsedAttribute('header'), filterData: parsedAttribute('filter-data'), show: (el.attr("ng-if") ? function (scope) { diff --git a/src/scripts/ngTableColumn.js b/src/scripts/ngTableColumn.js index 62f33669..d013e3a3 100644 --- a/src/scripts/ngTableColumn.js +++ b/src/scripts/ngTableColumn.js @@ -24,6 +24,7 @@ headerTitle: function(){ return ''; }, sortable: function(){ return false; }, summary: function() { return false; }, + summaryClass: function(){ return ''; }, show: function(){ return true; }, title: function(){ return ''; }, titleAlt: function(){ return ''; } From 47a6aef79de88242533ef3be6927e2c615bd974a Mon Sep 17 00:00:00 2001 From: Szymon Drosdzol Date: Mon, 31 Aug 2015 11:39:18 +0200 Subject: [PATCH 9/9] Added possibility to define filters for summary cells --- dist/ng-table.js | 6 ++++++ examples/demo35.html | 16 +++++++++++++--- src/scripts/ngTable.directive.js | 1 + src/scripts/ngTableColumn.js | 1 + src/scripts/ngTableSummaryRowController.js | 4 ++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/dist/ng-table.js b/dist/ng-table.js index e322d406..7ef5c6d9 100644 --- a/dist/ng-table.js +++ b/dist/ng-table.js @@ -410,6 +410,7 @@ sortable: function(){ return false; }, summary: function() { return false; }, summaryClass: function(){ return ''; }, + summaryFilter: function(){ return false; }, show: function(){ return true; }, title: function(){ return ''; }, titleAlt: function(){ return ''; } @@ -1402,6 +1403,7 @@ filter: parsedAttribute('filter'), summary: parsedAttribute('summary'), summaryClass: parsedAttribute('summary-class'), + summaryFilter: parsedAttribute('summary-filter'), headerTemplateURL: parsedAttribute('header'), filterData: parsedAttribute('filter-data'), show: (el.attr("ng-if") ? function (scope) { @@ -1730,6 +1732,10 @@ $scope.params.settings().summaries = $scope.$columns.map(function($column){ return $column.summary; }); + + $scope.params.settings().summaryFilters = $scope.$columns.map(function($column){ + return $column.summaryFilter; + }); } })(); diff --git a/examples/demo35.html b/examples/demo35.html index 7bc7e64f..c3fd682a 100644 --- a/examples/demo35.html +++ b/examples/demo35.html @@ -28,7 +28,7 @@

Table with summary footer

{{user.name}} + summary="'age'" summary-class="'test-class'" summary-filter="'currency'"> {{user.age}} @@ -69,7 +69,9 @@

Table with summary footer

var summaryValues = {}; var summaryFuncs = params.settings().summaries; - angular.forEach(summaryFuncs, function(summaryFunc) { + var summaryFilterFuncs = params.settings().summaryFilters; + + angular.forEach(summaryFuncs, function(summaryFunc, key) { summaryIndex = summaryFunc(); if (summaryIndex) { @@ -77,9 +79,17 @@

Table with summary footer

angular.forEach(collection, function(row){ summaryValues[summaryIndex] += row[summaryIndex]; }); + + var summaryFilter = summaryFilterFuncs[key](); + if (summaryFilter) { + var actualFilter = $filter(summaryFilter); + summaryValues[summaryIndex] = + actualFilter(summaryValues[summaryIndex]); + } } }); - params.summaryValues(summaryValues); + + params.summaryValues(summaryValues); $defer.resolve( collection.slice((params.page() - 1) * params.count(), diff --git a/src/scripts/ngTable.directive.js b/src/scripts/ngTable.directive.js index ac935bc2..77117c19 100644 --- a/src/scripts/ngTable.directive.js +++ b/src/scripts/ngTable.directive.js @@ -78,6 +78,7 @@ filter: parsedAttribute('filter'), summary: parsedAttribute('summary'), summaryClass: parsedAttribute('summary-class'), + summaryFilter: parsedAttribute('summary-filter'), headerTemplateURL: parsedAttribute('header'), filterData: parsedAttribute('filter-data'), show: (el.attr("ng-if") ? function (scope) { diff --git a/src/scripts/ngTableColumn.js b/src/scripts/ngTableColumn.js index d013e3a3..7a48277f 100644 --- a/src/scripts/ngTableColumn.js +++ b/src/scripts/ngTableColumn.js @@ -25,6 +25,7 @@ sortable: function(){ return false; }, summary: function() { return false; }, summaryClass: function(){ return ''; }, + summaryFilter: function(){ return false; }, show: function(){ return true; }, title: function(){ return ''; }, titleAlt: function(){ return ''; } diff --git a/src/scripts/ngTableSummaryRowController.js b/src/scripts/ngTableSummaryRowController.js index 11d0ca60..b55a0712 100644 --- a/src/scripts/ngTableSummaryRowController.js +++ b/src/scripts/ngTableSummaryRowController.js @@ -18,5 +18,9 @@ $scope.params.settings().summaries = $scope.$columns.map(function($column){ return $column.summary; }); + + $scope.params.settings().summaryFilters = $scope.$columns.map(function($column){ + return $column.summaryFilter; + }); } })();