Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pagination not working after loading JSON data on Ng-Table

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

like image 450
user2901633 Avatar asked Feb 11 '23 19:02

user2901633


1 Answers

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.

like image 181
kvothe Avatar answered Feb 14 '23 07:02

kvothe