Total Items in footer issue
Total Items in the footer does not show the $scope.pagingOptions.totalServerItems I configured. Instead, it reads from grid.config.totalServerItems.
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
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?
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
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.)
once the promise resolves a $digest shold be triggered. can you repro in a plunker?
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.
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.
Example http://plnkr.co/edit/4LyAek?p=preview from http://angular-ui.github.io/ng-grid/ have this bug too.
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)."
There's another issue, when I page the itens, and change page selected itens becomes null.
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();
}
};
I used $scope.gridApi.grid.option.totaltems and it is started working
I agree with @nkantkumar: $scope.gridApi.grid.option.totalItems properly sets the footer's totalItem count.