我正在使用
ng-table插件对这样的表进行分页:
$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都会调用getData()函数.并再次点击整个事物并获取所有记录并显示它们.因此,分页基本上是无用的.
我需要有一个客户端分页.是否可以使用ng-table?
试过这个
$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; } }); });
与上面的结果相同!
使用最新版本的ng-table,我最终使用以下内容:
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 }); }); } }
由于数据集,客户端分页正常工作.
对OP来说应该是这样的:
$http.get($rootScope.app.authApi + 'questions/' + selectedSubtopic.id) .success(function(result){ $scope.ngtableParams = new ngTableParams({count:5},{ counts:[],total:result.length,dataset: result // might be data instead of dataset depending on ng-table version }); });