Reloading ng-table doesn't work

I created ng-table

as:

data = $scope.publications;
        $scope.tablePublications = new ngTableParams({
       page: 1,            // show first page
       count: 20      // count per pages
    }, {
       total: data.length, // length of data
       getData: function($defer, params) {
           // use build-in angular filter
           var orderedData = params.sorting() ?
                               $filter('orderBy')(data, params.orderBy()) :
                               data;

       $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
   }
});

      

The lookup calls a function that fetches information from the API and then calls the function reloadTable

:

$scope.reloadTable = function(publications){
    $scope.tablePublications.data = publications;
    $scope.tablePublications.reload();
    $scope.tablePublications.reloadPages();
  }

      

Now $scope.tablePublications.data

contains new information, but .reload()

does not work and does not update the table.

I am changing the code for this

$scope.search = function(page){
    if($scope.searchText!=="" || $scope.searchText !== "undefined")
    {
        $scope.isSearch=true;
        Minisite.searchPublications({search: $scope.searchText, page: page}, function(publications){
            $scope.total=publications.total;
            $scope.publications = publications.publications;
            $scope.tablePublications.data = {};
            $scope.tablePublications.reload();
        });
    }
}

      

Minisite is a factory that fetches the hash from the API and then reloads my tables, but doesn't work. I have similar code in other functions and it works fine and I don't understand it.

+3


source to share


1 answer


In fact, since you are probably outside the digest loop, given that you are calling the api, you should try $scope.$apply()

like this:



$scope.$apply(function() {
    $scope.reloadTable = function(publications){
        $scope.tablePublications.data = publications;
        $scope.tablePublications.reload();
        $scope.tablePublications.reloadPages();
    }
});

      

+1


source







All Articles