When the last item is removed from a table on page 2 or greater, the paginate navigation disappears.
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10, // count per page
sorting: {
firstName: 'asc' // initial sorting
}
}, {
total: 0,
getData: function ($defer, params) {
$scope.myData = angular.copy($scope.clients, []);
var filteredData = params.filter() ? $filter('filter')($scope.myData, params.filter()) : $scope.myData;
var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : filteredData;
params.total(orderedData.length);
var data = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
//EXTRA CHECK
if (data.length === 0 && params.page() !== 1){
params.page(params.page()-1);
filteredData = params.filter() ? $filter('filter')($scope.myData, params.filter()) : $scope.myData;
orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : filteredData;
params.total(orderedData.length);
data = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
}
$defer.resolve(data);
}
});
I got around it with the above check to see if the filtered data comes back empty and if we're not on page one. Is there a built in way to manage this that I am overlooking?
+1. I've got the same issue as above.
As a workaround, you can check If the current row is the last one on that page and it's not the first page
if ($scope.tableParams.data.length == 1 && vm.tableParams.page() != 1) {
$scope..tableParams.page(vm.tableParams.page() - 1);
}
$scope.tableParams.reload();
That's what I've done in the past.
I don't think ngTable is going to be monitoring the dataset any time soon
(this would introduce potential performance problems). So I would suggest
going with this as a solution.
On Tue, Feb 7, 2017 at 9:46 AM, M.Msallati notifications@github.com wrote:
As a workaround, you can ckeck If the current row is the last one on that
page and it's not the first pageif ($scope.tableParams.data.length == 1 && vm.tableParams.page() != 1) {
$scope..tableParams.page(vm.tableParams.page() - 1); }
$scope..tableParams.reload();—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/esvit/ng-table/issues/720#issuecomment-277949435, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AA2HPnt6g1_cHsg4NhwX9VKNbwHuzASsks5raD2HgaJpZM4GLPEq
.
I've also used @msallati workaround in the past. Works pretty good but it would be nice to add this fix to the ngTable as it is a little bit annoying... It's only one check during deleting operation so I think it won't be a performance hit for overall library.
The problem is that ngTable doesn't "know" about the delete operation.
ngTable would need to watch the dataset for changes - this would be a
performance problem
On Tue, Feb 7, 2017 at 10:04 AM, Jakub Powierza notifications@github.com
wrote:
I've also used @msallati https://github.com/msallati workaround in the
past. Works pretty good but it would be nice to add this fix to the ngTable
as it is a little bit annoying... It's only one check during deleting
operation so I think it won't be a performance hit for overall library.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/esvit/ng-table/issues/720#issuecomment-277953666, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AA2HPo3igPmhmaPxxusbi-rJ1YreOLGqks5raEGigaJpZM4GLPEq
.
Thanks for your explanation! Now I can fully understand what's going on :)
Most helpful comment
I've also used @msallati workaround in the past. Works pretty good but it would be nice to add this fix to the ngTable as it is a little bit annoying... It's only one check during deleting operation so I think it won't be a performance hit for overall library.