4

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

user2901633
  • 989
  • 1
  • 8
  • 15

2 Answers2

8

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.

kelsier
  • 4,050
  • 5
  • 34
  • 49
  • interesting, will read more about it later, thanks for the solution. – user2901633 Oct 16 '14 at 03:18
  • 1
    your ng-repeat you must use $data – yunus kula Feb 23 '15 at 11:51
  • 1
    This is wrong. See http://plnkr.co/edit/IUzNp0bHdRZT4NUanmyz?p=preview, where I use `dataset`. At first, I was tempted to believe this answer because of the upvotes and because (as a test) removing the ng-table.js source `ng-table/pager.html`'s attribute that looks like the following made it work: `ng-if="params.data.length`. But that's not the real issue. Is this answer referring to scope level variables, as in, properties? Otherwise it makes no sense. I'd love more detail. – Tyler Collier Jun 21 '15 at 03:35
  • @yunuskula Thanks. Didn't see that. – kelsier Jun 22 '15 at 10:29
  • 1
    @TylerCollier Updated my answer. – kelsier Jun 22 '15 at 10:29
  • I've updated my plunker to show that you don't need to use $data in the ng-repeat (although it might be considered convenient). – Tyler Collier Jun 22 '15 at 12:59
  • My previous plunker used the latest version of the ng-table library. I wondered if the problem was from version 0.3.0 so I [made another plunker](http://plnkr.co/edit/IUzNp0bHdRZT4NUanmyz?p=preview) with the old version, but it still has nothing to do with $data or data. – Tyler Collier Jun 22 '15 at 13:36
0

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

Community
  • 1
  • 1
Kostia Mololkin
  • 868
  • 9
  • 25