Skip to content

Commit

Permalink
Merge pull request #357 from ghiscoding/bugfix/row-selection-when-rem…
Browse files Browse the repository at this point in the history
…oving-pagination

fix(services): toggle pagination was not displaying all row selection
  • Loading branch information
ghiscoding authored May 28, 2021
2 parents 03a8397 + e51ccb4 commit 6daec5e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ describe('PaginationService', () => {

expect(sharedService.gridOptions.enablePagination).toBeTrue();
expect(gotoSpy).toHaveBeenCalled();
expect(pubSubSpy).toHaveBeenNthCalledWith(3, `onPaginationVisibilityChanged`, { visible: true });
expect(pubSubSpy).toHaveBeenCalledWith(`onPaginationVisibilityChanged`, { visible: true });
expect(setPagingSpy).toHaveBeenCalledWith({ pageSize: mockGridOption.pagination!.pageSize, pageNum: 0 });
});
});
Expand Down
9 changes: 6 additions & 3 deletions packages/common/src/services/pagination.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,11 @@ export class PaginationService {
*
* IMPORTANT NOTE:
* The Pagination must be created on initial page load, then only after can you toggle it.
* Basically this method WILL NOT WORK to show the Pagination if it was not there from the start.
* Basically this method WILL NOT WORK to show the Pagination if it was never created from the start.
*/
togglePaginationVisibility(visible?: boolean) {
if (this.grid && this.sharedService?.gridOptions) {
const isVisible = visible !== undefined ? visible : !this.sharedService.gridOptions.enablePagination;
this.sharedService.gridOptions.enablePagination = isVisible;
this.pubSubService.publish(`onPaginationVisibilityChanged`, { visible: isVisible });

// make sure to reset the Pagination and go back to first page to avoid any issues with Pagination being offset
if (isVisible) {
Expand All @@ -312,6 +310,11 @@ export class PaginationService {
const pageSize = visible ? this._itemsPerPage : 0;
this.dataView.setPagingOptions({ pageSize, pageNum: 0 });
}

// finally toggle the "enablePagination" flag and make sure it happens AFTER the setPagingOptions is called (when using local grid)
// to avoid conflict with GridState bindSlickGridRowSelectionToGridStateChange() method
this.sharedService.gridOptions.enablePagination = isVisible;
this.pubSubService.publish(`onPaginationVisibilityChanged`, { visible: isVisible });
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/cypress/integration/example07.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('Example 07 - Row Move & Checkbox Selector Selector Plugins', { retries
.should('have.length', 4);
});

it('should expect row to be moved to another row index', () => {
it('should expect the row to have moved to another row index', () => {
cy.get('.slick-viewport-top.slick-viewport-left')
.scrollTo('top');

Expand Down

0 comments on commit 6daec5e

Please sign in to comment.