Reputation: 81
I created a ng-table
like:
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()));
}
});
When searching, a function is called that retrieves info from API and then calls the reloadTable
function:
$scope.reloadTable = function(publications){
$scope.tablePublications.data = publications;
$scope.tablePublications.reload();
$scope.tablePublications.reloadPages();
}
Now $scope.tablePublications.data
has a new information but .reload()
doesn't work and doesn't refresh the table.
I change my code for that
$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 retrieve hash from API, and then i reloaded my tablePublications but doesn´t work. I have similar code in other functions and work fine and i dont understand it.
Upvotes: 3
Views: 1611
Reputation: 8117
Actually, since you are probably outside of the digest cycle given that you are calling an api, you should try $scope.$apply()
like so:
$scope.$apply(function() {
$scope.reloadTable = function(publications){
$scope.tablePublications.data = publications;
$scope.tablePublications.reload();
$scope.tablePublications.reloadPages();
}
});
Upvotes: 1