question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
jpowie01commented, 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.

2reactions
christianaccacommented, Feb 7, 2017

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 page

if ($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 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

delete the last row in a table using sql query? - Stack Overflow
The query I tried for this is as follows: DELETE MAX(`id`) FROM `marks`;. There are 8 columns in the table. I want ...
Read more >
How to delete last record (on condition) from a table in MySQL?
To delete last record (on condition) from a table, you need to use ORDER BY DESC with LIMIT. 1. The syntax is as...
Read more >
Delete last row of table on document without affecting pages ...
Click in the left margin outside row 14 to select the whole row. · If there's any text in the row, press the...
Read more >
SQL Delete Row Statement - How to Remove Data From a ...
I have used this statement many times to clear a table after it was filled with test data. This approach allows us to...
Read more >
Overview of the SQL Delete statement - SQLShack
To remove a row from a table is accomplished through a Data Manipulation Language, aka DML statement, using the delete keyword.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found