Guest User

Untitled

a guest
Apr 24th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <ion-content padding-horizontal padding #content class="page-list-content">
  2. <ion-infinite-scroll *ngIf="!isPagingComplete" (ionInfinite)="doInfinite($event)" position="bottom">
  3. <ion-infinite-scroll-content></ion-infinite-scroll-content>
  4. </ion-infinite-scroll>
  5. <ion-list>
  6. <ion-item-sliding *ngFor="let entity of entityList" #item>
  7. <ion-item (click)="config.onItemClick(entity)" >
  8. <template [ngTemplateOutlet]="template" [ngOutletContext]="{entity: entity}"></template>
  9. </ion-item>
  10. <ion-item-options side="right">
  11. <button ion-button color="danger" *ngIf="config && config.canDelete" (click)="delete(entity.id)">
  12. <ion-icon name="trash"></ion-icon>Delete
  13. </button>
  14. <button ion-button color="dark" >
  15. <ion-icon name="more"></ion-icon>More
  16. </button>
  17. </ion-item-options>
  18. </ion-item-sliding>
  19. <ion-list-header>
  20. <button *ngIf="config && config.canCreate" (click)="create()"
  21. ion-button full color="secondary">
  22. Create New<ion-icon name="add"></ion-icon>
  23. </button>
  24. </ion-list-header>
  25. </ion-list>
  26. </ion-content>
  27.  
  28. doInfinite(infiniteScroll) {
  29. console.log('Begin async operation');
  30.  
  31. setTimeout(() => {
  32.  
  33. this.getPaginatedList(infiniteScroll);
  34. console.log('Async operation has ended');
  35. }, 500);
  36. }
  37.  
  38. getPaginatedList(infiniteScroll) {
  39.  
  40. if (this.isPagingComplete) {
  41. infiniteScroll.complete();
  42. return;
  43. }
  44.  
  45. this.getNextPage(infiniteScroll);
  46. }
  47.  
  48. getPage(pageNumber: number = 1)
  49. {
  50. this.pageNumber = pageNumber
  51. this.getNextPage();
  52. }
  53.  
  54. getNextPage(infiniteScroll?: any)
  55. {
  56. if(!this.isPagingEnabled || this.isPagingComplete)
  57. {
  58. return;
  59. }
  60.  
  61. this.isPagingEnabled = false;
  62. this.getList(this.pageSize, this.pageNumber).subscribe(entities => {
  63. //Clear the list if this is the first page loaded
  64. //Clear the page in the subscribe to have double buffering effect
  65. if(this.pageNumber == 1)
  66. {
  67. this.entityList = [];
  68. }
  69.  
  70. this.entityList = this.entityList.concat(entities);
  71.  
  72. this.pageNumber++;
  73. if(this.pageSize > entities.length)
  74. {
  75. this.isPagingComplete = true;
  76. }
  77. }, () => {},
  78. () => {
  79. this.isPagingEnabled = true;
  80. if (infiniteScroll) {
  81. infiniteScroll.complete();
  82. }
  83. });
  84. }
Add Comment
Please, Sign In to add comment