简体   繁体   中英

limit pagination in angular4

I try apply pagination in angular4 but I don't khnow how to apply limit in pagination .. limit : for example I have 1000 pagination how to display in the first 5 pagination then ... then last page : 1 2 3 4 5 .... 1000. in my code I display all pagination 1000 pagination but isn't not good design for client:

code component:

addClass(x)
{
    $(".page-item").click(function () {
        $(this).addClass("current").siblings().removeClass('current');
    });
}

next()
{ 
    $('.current').next('.page-item').trigger('click'); 
}
previous()
{
     $('.current').prev('.page-item').trigger('click'); 
}

code html:

<ul>
   <li class="previous" (click)="previous()">Previous</li>
   <li class="next" (click)="next()">Next</li>
</ul>
<ul class="pagination">
<li *ngFor="let x of pages" class='page-item' (click)='addClass(x)'>
    {{x}}
</li>

and this is screenshot of display in my page:

在此处输入图片说明

Some hint:

  • You create a pages array containing 1,2,3,4,5... MAX before loading the html
  • When clicking next, previous or directly on a page, you recreate the array, if the new page is greater than current +/- 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM