I'm trying to implement server-side pagination on an AngujarJS app but haven't figured out how to get the grand total (not the per-request total) items in a given JSON response without having to do an additional request:
$scope.books = [];
$scope.limit = 3;
$scope.offset = 0;
$scope.search = function () {
Books.query({ q: $scope.query, limit: $scope.limit, offset: $scope.offset },
function (response) {
$scope.books = response;
}
);
};
$scope.previous = function () {
if ($scope.offset >= $scope.limit) {
$scope.offset = $scope.offset - $scope.limit;
$scope.search();
}
}
$scope.next = function () {
if ($scope.offset <= $scope.limit) {
$scope.offset = $scope.offset + $scope.limit;
$scope.search();
}
}
I've been looking at great contributed directives such as ng-table
and ng-grid
which already implement this as well as other useful features but I just want to be able to implement this one functionality from scratch to really learn the basics.
$scope.limit
– Coolish