Assuming you are using one of the older versions of ng-table script, the first step is to get the data from your api service and then to initialize the ng-table options you want.
Using the $http service, you will receive data only ONE TIME if the request is successful, and inside this service, initialize ngTableParams. This way you avoid multiple callback problems.
Notice also the changes in the getData part, how ordering and filtering are resolved with pagination.
Here is the solution I used for my projects, hope this helps.
$http.get('/api/questions').success(function (data) { $scope.questionTable = new ngTableParams({ page: 1, count: 10 }, { total: data.length, getData: function ($defer, params) { var filteredData = params.filter() ? $filter('filter')(data, params.filter()) : data; var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : data; params.total(orderedData.length); $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); } }); });
source share