Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting row from ngTable when it's the last item on page #720

Open
wayjake opened this issue Oct 8, 2015 · 6 comments
Open

Deleting row from ngTable when it's the last item on page #720

wayjake opened this issue Oct 8, 2015 · 6 comments

Comments

@wayjake
Copy link

wayjake commented Oct 8, 2015

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?

@jpowie01
Copy link

jpowie01 commented Jun 3, 2016

+1. I've got the same issue as above.

@msallati
Copy link

msallati commented Feb 7, 2017

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();

@christianacca
Copy link
Collaborator

christianacca commented Feb 7, 2017 via email

@jpowie01
Copy link

jpowie01 commented Feb 7, 2017

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.

@christianacca
Copy link
Collaborator

christianacca commented Feb 7, 2017 via email

@jpowie01
Copy link

jpowie01 commented Feb 7, 2017

Thanks for your explanation! Now I can fully understand what's going on :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants