Pagination with ng-table in angular

I use the ng-table plugin to split the table as follows:

$scope.ngtableParams = new ngTableParams({}, { counts:false, getData: function(params) { return $http.get($rootScope.app.authApi + 'questions/' + selectedSubtopic.id).then(function(data) { params.total(data.data.length); return data.data; }); } }); 

Funnily ng-table calls the getData () function every time a user clicks on page numbers. And again it hits everything, extracts all the records and displays them. Thus pagination is practically useless.

I need to have a pagination client. Is this possible with ng-table?

Tried it also

 $http.get($rootScope.app.authApi + 'questions/' + selectedSubtopic.id) .success(function(data){ $scope.ngtableParams = new ngTableParams({count:5}, { counts:[], paginationMaxBlocks: 13, paginationMinBlocks: 2, total:data.length, getData: function(params) { return data; } }); }); 

The same with the above!

+8
angularjs pagination ngtable
source share
2 answers

With the latest ng table version, I end up using the following:

 function IssueCtrl(NgTableParams, IssueService) { var self = this; loadTable(); function loadTable() { IssueService.getIssues().then(function (issues) { self.tableParams = new NgTableParams({ page: 1, count: 5 }, { dataset: issues // might be data instead of dataset depending on ng-table version }); }); } } 

On the dataset page, pagination of the client works correctly.

So for the OP, it should be something like this:

 $http.get($rootScope.app.authApi + 'questions/' + selectedSubtopic.id) .success(function(result){ $scope.ngtableParams = new ngTableParams({count:5}, { counts:[], paginationMaxBlocks: 13, paginationMinBlocks: 2, total:result.length, dataset: result // might be data instead of dataset depending on ng-table version }); }); 
+1
source share

ng-table has a lot of problems. I will switch my code to jquery datatable . Give it a try.

0
source share

All Articles