Commit 6af675ae by Nakarin Luankla

แก้ bug pagination

parent 70bbdb4d
...@@ -144,6 +144,6 @@ export class SubJobPositionIndicatorsComponent { ...@@ -144,6 +144,6 @@ export class SubJobPositionIndicatorsComponent {
positionClass: 'toast-top-right', positionClass: 'toast-top-right',
}) })
} }
} }
\ No newline at end of file
...@@ -31,12 +31,12 @@ ...@@ -31,12 +31,12 @@
<!-- ตัวเลือกจำนวนรายการต่อหน้า --> <!-- ตัวเลือกจำนวนรายการต่อหน้า -->
<li> <li>
<select class="ti-form-select" [(ngModel)]="pageSize" (ngModelChange)="onPageSizeChange()"> <select class="ti-form-select" [(ngModel)]="pageSize" (ngModelChange)="onPageSizeChange()">
<option *ngFor="let size of pageSizes" [value]="size">{{ size }}</option> <option *ngFor="let size of pageSizes" [ngValue]="size">รายการต่อหน้า: {{ size }}</option>
</select> </select>
</li> </li>
</ul> </ul>
<ul class="nav-tabs mt-3"> <ul class="nav-tabs mt-3">
<span>Show {{ (currentPage - 1) * pageSize + 1 }} to {{ getEndIndex() }} of {{ totalItems }} items</span> <span >แสดง {{ (currentPage - 1) * pageSize + 1 }} ถึง {{ getEndIndex() }} จาก {{ totalItems }} รายการ</span>
</ul> </ul>
</nav> </nav>
...@@ -11,14 +11,13 @@ export class PaginationComponent { ...@@ -11,14 +11,13 @@ export class PaginationComponent {
currentPage = 1; currentPage = 1;
@Output() pageChange = new EventEmitter<number>(); @Output() pageChange = new EventEmitter<number>();
@Output() pageSizeChange = new EventEmitter<number>(); @Output() pageSizeChange = new EventEmitter<number>();
constructor(private cdr: ChangeDetectorRef) { } constructor(private cdr: ChangeDetectorRef) { }
pageSizes = [10, 20, 50, 100]; pageSizes: number[] = [10, 20, 50, 100];
ngOnChanges() { ngOnChanges() {
this.changePage(1) this.changePage(1)
this.cdr.detectChanges(); this.cdr.detectChanges();
}
}
get totalPages(): number { get totalPages(): number {
return Math.ceil(this.totalItems / this.pageSize); return Math.ceil(this.totalItems / this.pageSize);
} }
...@@ -33,7 +32,7 @@ ngOnChanges() { ...@@ -33,7 +32,7 @@ ngOnChanges() {
} }
pages.push(1); pages.push(1);
if (current > 3) pages.push('...'); if (current > 3) pages.push('...');
const middlePages = [current - 1, current, current + 1].filter(p => p > 1 && p < total); const middlePages = [current - 1, current, current + 1].filter(p => p > 1 && p < total);
pages.push(...middlePages); pages.push(...middlePages);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment