Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a server side pagination with angularjs $resource ?

Tags:

angularjs

I am trying to display a table with a large collection of elements. I want to paginate the table and load only the elements displayed on the current page. Now, the json is loaded with $resource.

I read here that it's a good idea to pass the pagination infos (currentPage, pagesCount and elementsCount) inside the json header.

How can I access to those infos which are in the json header from angular?

Here is the basic js structure:

angular.module('App.services', ['ngResource']).
factory('List', function($resource){
    return $resource('url/of/json/:type/:id', {type:'@type', id:'@id'});
});


angular.module('App.controllers', []).
controller('ListCtrl', ['$scope', 'List', function($scope, List) {
    var $scope.list= List.query({offset: 0, limit: 100, sortType: 'DESC' });
}]);
like image 427
François Romain Avatar asked Jul 04 '13 00:07

François Romain


People also ask

Is pagination server side or client-side?

Operations and Engineering Dashboards supports server side pagination grid. Server side pagination is considered useful for large-sets of data as the amount of data that is transferred to the client is much smaller than the data handled by the client.

What is server side pagination in angular?

Server-Side Paging (Angular) Server-side paging consists of making requests that bring in one page of data at a time. The actual commands used to retrieve the data depend on the API exposed by the server.

What is server pagination?

Server-side pagination is a way of controlling a subset of data requests that were fetched from a client-side server, and are useful if we don't want to display all of the data at once. Server-side pagination requires the client to pass in a parameter in order to fetch the relevant information.

What is pagination in AngularJS?

Pagination in AngularJS is a technique of dividing the contents of a particular large page into small pages and showing them in an indexed format in order. This technique is very popular in designing search engines in which, the most relatable content is presented on a priority basis.


1 Answers

Based on the AngularJS $resource documentation, it should be possible to do this:

List.query({offset: 0, limit: 100, sortType: 'DESC' }, function(data, responseHeaders) {
  // you can access headers here
});
like image 171
holographic-principle Avatar answered Oct 15 '22 14:10

holographic-principle