Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit a220d91

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
fix(pagination): fixed a few pagination problem used by backend service
- also fixed GraphQL to work correctly when "enablePagination" is set to False, it shouldn't add pagination into the GraphQL query (first, offset)
1 parent b112ea9 commit a220d91

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
638638
if (!this.gridOptions.pagination) {
639639
this.gridOptions.pagination = (this.gridOptions.pagination) ? this.gridOptions.pagination : undefined;
640640
}
641-
if (this.gridOptions.pagination && totalCount) {
641+
if (this.gridOptions.pagination && totalCount !== undefined) {
642642
this.gridOptions.pagination.totalItems = totalCount;
643643
}
644644
if (this.gridOptions.presets && this.gridOptions.presets.pagination && this.gridOptions.pagination) {

src/app/modules/angular-slickgrid/components/slick-pagination.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<div class="slick-pagination-nav">
33
<nav aria-label="Page navigation">
44
<ul class="pagination">
5-
<li class="page-item" [ngClass]="pageNumber === 1 ? 'disabled' : ''">
5+
<li class="page-item" [ngClass]="(pageNumber === 1 || totalItems === 0) ? 'disabled' : ''">
66
<a class="page-link icon-seek-first fa fa-angle-double-left" aria-label="First" (click)="changeToFirstPage($event)">
77
</a>
88
</li>
9-
<li class="page-item" [ngClass]="pageNumber === 1 ? 'disabled' : ''">
9+
<li class="page-item" [ngClass]="(pageNumber === 1 || totalItems === 0) ? 'disabled' : ''">
1010
<a class="page-link icon-seek-prev fa fa-angle-left" aria-label="Previous" (click)="changeToPreviousPage($event)">
1111
</a>
1212
</li>
@@ -15,17 +15,17 @@
1515

1616
<div class="slick-page-number">
1717
<span [translate]="'PAGE'"></span>
18-
<input type="text" class="form-control" value="{{pageNumber}}" size="1" (change)="changeToCurrentPage($event)">
18+
<input type="text" class="form-control" [value]="pageNumber" size="1" [readOnly]="totalItems === 0" (change)="changeToCurrentPage($event)">
1919
<span [translate]="'OF'"></span><span> {{pageCount}}</span>
2020
</div>
2121

2222
<nav aria-label="Page navigation">
2323
<ul class="pagination">
24-
<li class="page-item" [ngClass]="pageNumber === pageCount ? 'disabled' : ''">
24+
<li class="page-item" [ngClass]="(pageNumber === pageCount || totalItems === 0) ? 'disabled' : ''">
2525
<a class="page-link icon-seek-next text-center fa fa-lg fa-angle-right" aria-label="Next" (click)="changeToNextPage($event)">
2626
</a>
2727
</li>
28-
<li class="page-item" [ngClass]="pageNumber === pageCount ? 'disabled' : ''">
28+
<li class="page-item" [ngClass]="(pageNumber === pageCount || totalItems === 0) ? 'disabled' : ''">
2929
<a class="page-link icon-seek-end fa fa-lg fa-angle-double-right" aria-label="Last" (click)="changeToLastPage($event)">
3030
</a>
3131
</li>

src/app/modules/angular-slickgrid/components/slick-pagination.component.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ export class SlickPaginationComponent implements AfterViewInit, OnDestroy {
9090
}
9191

9292
changeToCurrentPage(event: any) {
93-
this.pageNumber = event.currentTarget.value;
93+
this.pageNumber = +event.currentTarget.value;
9494
if (this.pageNumber < 1) {
95-
this.pageNumber = 1;
95+
this.pageNumber = 1;
9696
} else if (this.pageNumber > this.pageCount) {
97-
this.pageNumber = this.pageCount;
97+
this.pageNumber = this.pageCount;
9898
}
9999

100100
this.onPageChanged(event, this.pageNumber);
@@ -110,7 +110,7 @@ export class SlickPaginationComponent implements AfterViewInit, OnDestroy {
110110
onChangeItemPerPage(event: any) {
111111
const itemsPerPage = +event.target.value;
112112
this.pageCount = Math.ceil(this.totalItems / itemsPerPage);
113-
this.pageNumber = 1;
113+
this.pageNumber = (this.totalItems > 0) ? 1 : 0;
114114
this.itemsPerPage = itemsPerPage;
115115
this.onPageChanged(event, this.pageNumber);
116116
}
@@ -221,7 +221,13 @@ export class SlickPaginationComponent implements AfterViewInit, OnDestroy {
221221
}
222222

223223
recalculateFromToIndexes() {
224-
this.dataFrom = (this.pageNumber * this.itemsPerPage) - this.itemsPerPage + 1;
225-
this.dataTo = (this.totalItems < this.itemsPerPage) ? this.totalItems : (this.pageNumber * this.itemsPerPage);
224+
if (this.totalItems === 0) {
225+
this.dataFrom = 0;
226+
this.dataTo = 0;
227+
this.pageNumber = 0;
228+
} else {
229+
this.dataFrom = (this.pageNumber * this.itemsPerPage) - this.itemsPerPage + 1;
230+
this.dataTo = (this.totalItems < this.itemsPerPage) ? this.totalItems : (this.pageNumber * this.itemsPerPage);
231+
}
226232
}
227233
}

src/app/modules/angular-slickgrid/services/graphql.service.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,18 @@ export class GraphqlService implements BackendService {
104104
}
105105

106106
// add dataset filters, could be Pagination and SortingFilters and/or FieldFilters
107-
const datasetFilters: GraphqlDatasetFilter = {
108-
...this.options.paginationOptions,
109-
first: ((this.options.paginationOptions && this.options.paginationOptions.first) ? this.options.paginationOptions.first : ((this.pagination && this.pagination.pageSize) ? this.pagination.pageSize : null)) || this.defaultPaginationOptions.first
110-
};
107+
let datasetFilters: GraphqlDatasetFilter = {};
108+
109+
// only add pagination if it's enabled in the grid options
110+
if (this._gridOptions.enablePagination !== false) {
111+
datasetFilters = {
112+
...this.options.paginationOptions,
113+
first: ((this.options.paginationOptions && this.options.paginationOptions.first) ? this.options.paginationOptions.first : ((this.pagination && this.pagination.pageSize) ? this.pagination.pageSize : null)) || this.defaultPaginationOptions.first
114+
};
111115

112-
if (!this.options.isWithCursor) {
113-
datasetFilters.offset = ((this.options.paginationOptions && this.options.paginationOptions.hasOwnProperty('offset')) ? +this.options.paginationOptions['offset'] : 0);
116+
if (!this.options.isWithCursor) {
117+
datasetFilters.offset = ((this.options.paginationOptions && this.options.paginationOptions.hasOwnProperty('offset')) ? +this.options.paginationOptions['offset'] : 0);
118+
}
114119
}
115120

116121
if (this.options.sortingOptions && Array.isArray(this.options.sortingOptions) && this.options.sortingOptions.length > 0) {

0 commit comments

Comments
 (0)