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

Total Items in footer issue

Open richtmat opened this issue 13 years ago • 13 comments

Total Items in the footer does not show the $scope.pagingOptions.totalServerItems I configured. Instead, it reads from grid.config.totalServerItems.

richtmat avatar Apr 12 '13 13:04 richtmat

we switched out the place where totalServerItems is set because people wanted to update it manually while watching the pagingOptions configuration variable for changes (so they know when to retrieve more data from the server).

On Fri, Apr 12, 2013 at 6:44 AM, richtmat [email protected] wrote:

Total Items in the footer does not show the $scope.pagingOptions.totalServerItems I configured. Instead, it reads from grid.config.totalServerItems.

— Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/ng-grid/issues/332 .

-Tim Sweet

orneryd avatar Apr 12 '13 15:04 orneryd

OK now I set $scope.gridOptions.totalServerItems statically and if totalServerItems > pageSize I can see that value.

But if I use a $http call to get the items from the server totalServerItems is not set (maybe because of async?). Also the maxRows() function from ngFooter Controller is called only once. How do I trigger another call?

richtmat avatar Apr 15 '13 10:04 richtmat

are you using the $http or $timeout services? because it should just be a digest once the values have been updated. if you are going an ajax call then you are outside of the angular context and you may have to manually trigger a $digest. The $http/$timeout service automatically triggers a $digest after the promise is resolved.

On Mon, Apr 15, 2013 at 3:05 AM, richtmat [email protected] wrote:

OK now I set $scope.gridOptions.totalServerItems statically and if totalServerItems > pageSize I can see that value.

But if I use a $http call to get the items from the server totalServerItems is not set (maybe because of async?). Also the maxRows() function from ngFooter Controller is called only once. How do I trigger another call?

— Reply to this email directly or view it on GitHubhttps://github.com/angular-ui/ng-grid/issues/332#issuecomment-16376587 .

-Tim Sweet

orneryd avatar Apr 15 '13 18:04 orneryd

yes, I am using $http, encapsulated in a angular service at the first line of my controller. I don't think its a problem with $digest, because once all js is loaded for ng-grid, the footers maxRows is evaluated. That happens before the promise is resolved. I guess the databinding is not a two-way binding here because the model in the footer is a function. So when the promise finally is resolved nothing happens any more. Is there a way to trigger something like a re-rendering of the footer? (skip to last page button is not working either, same problem here.)

richtmat avatar Apr 16 '13 15:04 richtmat

once the promise resolves a $digest shold be triggered. can you repro in a plunker?

orneryd avatar Apr 16 '13 21:04 orneryd

here we go: http://plnkr.co/edit/tuCxztnymOF55SlGLeuj?p=preview

I have two ng-grid versions here to test. Using the old one leads to output of null, using 2.0.4 shows my initial value. Outside of the table the correct value is shown.

richtmat avatar Apr 17 '13 07:04 richtmat

hi @timothyswt , I'm still stuck on that issue. I dug into the sources and believe that the current implementation does not allow for a change of a once set totalServerItems value. I think it is necessary because of async retrieving that value from the server and because of regular changes in datasets which would not be updated.

richtmat avatar Apr 26 '13 10:04 richtmat

Example http://plnkr.co/edit/4LyAek?p=preview from http://angular-ui.github.io/ng-grid/ have this bug too.

timothyklim avatar Jun 14 '13 09:06 timothyklim

This is exactly what I was looking for. Now I know why they were split. "we switched out the place where totalServerItems is set because people wanted to update it manually while watching the pagingOptions configuration variable for changes (so they know when to retrieve more data from the server)."

jonricaurte avatar Jun 29 '13 06:06 jonricaurte

There's another issue, when I page the itens, and change page selected itens becomes null.

igorcosta avatar Jul 16 '14 19:07 igorcosta

I got this issue fixed by updating totalServerItems on every paging action $scope.setPagingData(data,page,pageSize); on success $scope.setPagingData = function(data, page, pageSize){
var pagedData = data.slice((page - 1) * pageSize, page * pageSize); $scope.myData = pagedData; $scope.totalServerItems = data.length; if (!$scope.$$phase) { $scope.$apply(); } };

varshaan0sharma avatar Nov 19 '15 11:11 varshaan0sharma

I used $scope.gridApi.grid.option.totaltems and it is started working

nkantkumar avatar Feb 24 '16 16:02 nkantkumar

I agree with @nkantkumar: $scope.gridApi.grid.option.totalItems properly sets the footer's totalItem count.

blakerego avatar Feb 26 '16 00:02 blakerego