Pagination not working after loading JSON data on Ng-Table

我的梦境 提交于 2019-12-07 09:16:27

问题


I followed the example on http://bazalt-cms.com/ for the pagination but using $http.get instead of hard-coding a variable in the controller.

  $http.get("data.json").success(function(data){
       $scope.dataset = data;
   }

I also moved the $scope.tableParams inside the $http.get

$http.get("data.json").success(function(data){
     $scope.dataset = data;

     $scope.tableParams = new ngTableParams({
      ...
    }
});

and changed the data variable to $scope.dataset

total: $scope.dataset.length, // length of data
getData: function($defer, params) {
        $defer.resolve($scope.dataset.slice((params.page() - 1) * params.count(), params.page() * params.count()));}

Everything works fine besides the pagination is now not working See Plnkr here


回答1:


I've been working with ng-table for a while. When I tried using variable names other than $data or data, it doesn't seem to work. So I suggest you should stick to using $data or data instead of any other variable names like dataset.

Here's a working Plunker.

UPDATE :

Looks like I missed to see what was really wrong in the OP's question. As Tyler Collier and yunus kala mentioned in the comments, you just have to use $data like <tr ng-repeat="user in $data"> instead of <tr ng-repeat="user in dataset">. And it doesn't matter if you use data or dataset in your controller code.




回答2:


have a look here ng-Table not rendering new data when reloading request
first should apply directive ng-repeat for $data variable,and move ngtableParams initialization outside success callback, and put inside getData all logic for data acsess



来源:https://stackoverflow.com/questions/26373825/pagination-not-working-after-loading-json-data-on-ng-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!