Deleting row from ngTable when it's the last item on page
See original GitHub issueWhen 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:
- Created 8 years ago
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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: