Here is what I understand by the if condition in the following code:
$scope.pagingOptions = {
pageSizes: [250, 500, 1000],
pageSize: 250,
currentPage: 1
};
$scope.$watch('pagingOptions', function (newVal, oldVal) {
if (newVal !== oldVal && newVal.currentPage !== oldVal.currentPage) {
$scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
}
}, true);
whenever the pagingOptions
changes and the currentPage
property has changed the if
conditions becomes true, so the getPagedDataAsync
method gets executed.
But even if I don't change the currentPage
but the pageSize
from the UI, the grid gets refreshed.
Which I don't expect to happen(according to my understanding). So why is that grid getting refreshed?
From here, I have taken the code:
http://angular-ui.github.io/ng-grid/ with the Server-Side Paging Example heading
The
true
at the end of the$watch
indicates a deep watch of the scope objectpagingOptions
.So, if
true
is passed in as on optional third parameter, Angular will do a deep equality check. Therefore, thepageSize
property will be checked for equality and will be different.Documentation for
$watch
and the third parameter[objectEquality]
is here.