Skip to content

Commit

Permalink
fix(data-grid): imporves pagination with 0 elements (#2316)
Browse files Browse the repository at this point in the history
* fix: pagination with 0 elements in data-grid
---------

Co-authored-by: Amir Baghdoust <[email protected]>
  • Loading branch information
JuliaaaaH and amir-ba authored Oct 24, 2024
1 parent c19759f commit 42a3b36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/components/src/components/pagination/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,24 @@ describe('pagination', () => {
})
);
});
it('should show no start element when total elements is zero', async () => {
const specPage = await newSpecPage({
components: [Pagination],
html: `<scale-pagination
hide-borders="true"
hide-border="true"
page-size="11"
start-element="0"
total-elements="0"
styles="style">
</scale-pagination>`,
});
const paginationInfoElement =
specPage.root.shadowRoot.querySelector('.pagination__info');
const buttonPrev = specPage.root.shadowRoot.querySelector(
'.pagination__prev-prompt'
);
expect(paginationInfoElement.textContent).toEqual('0-0 / 0');
expect(buttonPrev.hasAttribute('disabled')).toBe(true);
});
});
4 changes: 2 additions & 2 deletions packages/components/src/components/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ export class Pagination {
/* 10. Render */
render() {
const total = this.totalElements;
const start = this.startElement + 1;
const start = total === 0 ? 0 : this.startElement + 1;
const end = Math.min(this.startElement + this.pageSize, total);
const isAtStart = start === 1;
const isAtStart = start === 1 || total === 0;
const isAtEnd = end === total;
return (
<Host>
Expand Down

0 comments on commit 42a3b36

Please sign in to comment.