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.

DirPaginate: Update pagination on change data array

See original GitHub issue

Hey Michael,

Thanks a million for this directive it is amazing.

I’m using this directive in a custom table directive that I wrote. Items in the table can be deleted and new items could be added by the user. Now when I delete or add an items the pagination does NOT update by itself. I might be missing something but as far as I can see I can’t refresh the pagination with the current options.

Down to the question: Is the currently a way to update the pagination once the data array changes?

For all clearity. In the following example ‘items’ would be what I mean with data array:

<li dir-paginate="item in items | itemsPerPage: 10">{{ item }}</li>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelbromleycommented, Mar 26, 2015

Okay I see why you were getting that unexpected behaviour. You are correct in that this a an Angular-related issue rather than something specific to this module.

Here is how I would handle this: instead of an ng-if on the deleted property, you could add an additional filter using a custom predicate function:

<li dir-paginate="meal in meals | filter:deletedFilter | filter:q | itemsPerPage: pageSize" current-page="currentPage">
    <span class='delete-me-btn' ng-click="deleteMe(meal)">x</span>     <span>{{meal.value}}</span>
</li>
// controller
$scope.deleteMe = function(item) {
    item.deleted = true;
}

$scope.deletedFilter = function(item) {
    return !item.deleted;
};

Demo: http://plnkr.co/edit/Pl3BHqhngjxftzzrkEbC?p=preview

1reaction
michaelbromleycommented, Mar 23, 2015

Hi,

When you say “refresh”, do you mean that the collection length has not changed, but the contents themselves have changed?

As far as I am aware (and I just tested it out in plunker (http://plnkr.co/edit/jcQ6jFq6oGOn1VlUnoYl?p=preview), if you change the collection, it should update automatically.

This of course assumes that any changes made are done within the Angular digest cycle. That is to say, if your collection is modified by some code external to Angular, then you might have to call a $scope.$apply(); to force Angular to check the changes.

If none of that helps, please get back to me with more specifics of what you are trying to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dir-pagination directive angularjs - Stack Overflow
Update you booking list object inside your filter function . Since its two way data binding updating the booking list object might recalculate...
Read more >
Search filter is too slow in angularjs with large dataset
I have AngularJs client application which displays data in table using dir-paginate directive of dirPagination.js
Read more >
Simple Frontend Pagination | React - YouTube
In this video we will implement some custom pagination in React to get a certain number of fetched posts per page. We will...
Read more >
dir-pagination using $index, $first, $last etc. - Plunker
Code goes here var myApp = angular.module('myApp', ['angularUtils.directives.dirPagination']); function MyController($scope) { $scope.
Read more >
Server Side Pagination in AngularJS - Ciphertrick
At the client side again we will be using dir-paginate like we ... getData = function(pageno){ // This would fetch the data on...
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