michaelbromley / angularUtils

A place where I will collect useful re-usable Angular components that I make
MIT License
2k stars 858 forks source link

dirPagination: $index does not display properly over multiple pages. #444

Open danilohgds opened 7 years ago

danilohgds commented 7 years ago

Hi there,

I found that $index will not accumulate past the actual page per number count, so u cannot tell them index from your object properly.

I made a plunker where it shows that every page has $index going from 0 to 9 instead of properly going up.

http://plnkr.co/edit/kFR4SUptZowapfJKBy6F?p=preview

lucas-barros commented 7 years ago

That's the expected behavior for $index, in this case it is keeping the iterator offset for the current collection, which has been filtered and has max size of pageSize. If you want the iterator offset based on the unfiltered collection use collection.indexOf(item), like this this:

  <div dir-paginate="item in collection | filter:q | itemsPerPage: pageSize ">
      <input type="text" 
      class="form-control"
      ng-model="item.price"
      aria-describedby="basic-addon1">

      {{collection.indexOf(item)}}

  </div>