0

I am trying to use angular-UI pagination for a table, where I am splicing the array where the page intersects the array. However I am not clear how to handle the fact that the array of objects is being added to and deleted to from within the table itself.

Also, I am sorting through a filter by the name property of an object in my ng-repeat. I expect what's is item[0] in my model array, does not correlate with the first item being displayed in the table via ng-repeat...I could be wrong.

I am just looking for advice on how to implement paging when the ng-repeat sorts the list, and the collection size is changing all the time.

Regards

I

smackenzie
  • 2,880
  • 7
  • 46
  • 99

2 Answers2

3

you can try to use multiple filters at once for example:

ng-repeat="item in items | myFilter | limitTo:pageNumber*perPage | limitTo: -perPage"

This allow you to use your filter first on each collection/model change, then it show last "perPage" records dependig of "pageNumber".

Michał Ignaszewski
  • 1,124
  • 12
  • 11
  • Hi, the only filter I am using at the moment is an orderBy. This method seems easier than other examples I have seen where the table is bound to a filtered array and you have to keep splicing the array to keep in step with the page selections. It is this splicing which worries me when my view is sorted differently to the natural order in the collection. – smackenzie Sep 15 '14 at 18:38
0

Please see that demo : http://plnkr.co/edit/3nqRHUySsJZwpKQiMMTm?p=preview

just set watch to yourCollection.length

ie:

     $scope.$watch('yourCollection.length', function(){

        $scope.bigTotalItems = $scope.yourCollection.length;

      }

)
Vivz
  • 6,625
  • 2
  • 17
  • 33
sylwester
  • 16,498
  • 1
  • 25
  • 33
  • Hi, thanks...do you have to do the array splicing? Looking at Michaels response below, it seems to be all managed within the ng-repeat? – smackenzie Sep 15 '14 at 22:22
  • @user1754307 you can splice array straight inside repeater or you can do that using filters depends on you – sylwester Sep 15 '14 at 22:23
  • Hi, if you are ordering in the filter, I am concerned manually splicing the raw array won't take into account the sort order in the UI. – smackenzie Sep 15 '14 at 23:20
  • @user1754307 please see here example with ordering http://plnkr.co/edit/3nqRHUySsJZwpKQiMMTm?p=preview – sylwester Sep 15 '14 at 23:26
  • Thanks. In the plunker there is a reference in the pagination directive to numPages, but this isn't in the javascript I can see? – smackenzie Sep 17 '14 at 09:00
  • @user1754307 `numPages`is calculated by directive – sylwester Sep 17 '14 at 09:04
  • If you add this this to your html in the sorted plunker: {{bigTotalItems}} you will see the count doesnt match as you add items, and some items are repeated across pages. Also, when the plunker loads, there are 8 items in the array, and 3 pages of 3 items. – smackenzie Sep 17 '14 at 09:17
  • I think the problem is in the last page, it repeats items from the second from last page. – smackenzie Sep 17 '14 at 09:31
  • @user1754307 please see here http://plnkr.co/edit/3nqRHUySsJZwpKQiMMTm?p=preview I've added filter startFrom – sylwester Sep 17 '14 at 09:39