From 5ef2d66da078d465992673ff4b9ea1716002d2a0 Mon Sep 17 00:00:00 2001 From: keithharvey Date: Sun, 28 Apr 2013 17:07:59 -0500 Subject: [PATCH 1/2] Total Server Items Fix Changed total server items in the footer to calculate using $scope.totalServerItems. Updated ng-grid directive to watch for a string value passed in, similar to other two-way data binding properties. --- src/classes/footer.js | 8 ++++---- src/directives/ng-grid.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/classes/footer.js b/src/classes/footer.js index f4eea99dc4..8d5c79990a 100644 --- a/src/classes/footer.js +++ b/src/classes/footer.js @@ -1,6 +1,6 @@ var ngFooter = function ($scope, grid) { $scope.maxRows = function () { - var ret = Math.max(grid.config.totalServerItems, grid.data.length); + var ret = Math.max($scope.totalServerItems, grid.data.length); return ret; }; @@ -12,7 +12,7 @@ $scope.pageForward = function() { var page = $scope.pagingOptions.currentPage; - if (grid.config.totalServerItems > 0) { + if ($scope.totalServerItems > 0) { $scope.pagingOptions.currentPage = Math.min(page + 1, $scope.maxPages()); } else { $scope.pagingOptions.currentPage++; @@ -36,7 +36,7 @@ $scope.cantPageForward = function() { var curPage = $scope.pagingOptions.currentPage; var maxPages = $scope.maxPages(); - if (grid.config.totalServerItems > 0) { + if ($scope.totalServerItems > 0) { return !(curPage < maxPages); } else { return grid.data.length < 1; @@ -44,7 +44,7 @@ }; $scope.cantPageToLast = function() { - if (grid.config.totalServerItems > 0) { + if ($scope.totalServerItems > 0) { return $scope.cantPageForward(); } else { return true; diff --git a/src/directives/ng-grid.js b/src/directives/ng-grid.js index 9d4ac365b5..26e5709f89 100644 --- a/src/directives/ng-grid.js +++ b/src/directives/ng-grid.js @@ -28,7 +28,16 @@ }, true); } else { grid.buildColumns(); - } + } + if (typeof options.totalServerItems == "string") { + $scope.$parent.$watch(options.totalServerItems, function (a) { + if (!a) { + scope.totalServerItems = 1; + return; + } + $scope.totalServerItems = a; + }); + } // if it is a string we can watch for data changes. otherwise you won't be able to update the grid data if (typeof options.data == "string") { From 0c0b1047db0f2b5d1755de21d660a6a0a93a816e Mon Sep 17 00:00:00 2001 From: keithharvey Date: Mon, 29 Apr 2013 17:43:21 -0500 Subject: [PATCH 2/2] Fixed a typo --- src/directives/ng-grid.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/directives/ng-grid.js b/src/directives/ng-grid.js index 26e5709f89..910ed4d2f8 100644 --- a/src/directives/ng-grid.js +++ b/src/directives/ng-grid.js @@ -32,10 +32,10 @@ if (typeof options.totalServerItems == "string") { $scope.$parent.$watch(options.totalServerItems, function (a) { if (!a) { - scope.totalServerItems = 1; + $scope.totalServerItems = 1; return; } - $scope.totalServerItems = a; + $scope.totalServerItems = a; }); }