Last active
September 16, 2023 21:53
Revisions
-
gorkemozkan revised this gist
Sep 16, 2023 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,6 @@ class PaginationHelper { if (itemIndex < 0 || itemIndex >= this.itemCount()) { return -1; } return Math.floor(itemIndex / this.itemsPerPage); } createPagination() { -
gorkemozkan revised this gist
Sep 16, 2023 . 1 changed file with 5 additions and 17 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,40 +7,28 @@ class PaginationHelper { return this.collection.length; } pageCount() { return Math.ceil(this.itemCount() / this.itemsPerPage); } pageItemCount(pageIndex) { const pages = this.createPagination(); return pages[pageIndex]?.length ?? -1; } pageIndex(itemIndex) { if (itemIndex < 0 || itemIndex >= this.itemCount()) { return -1; } return Math.floor(itemIndex / this.itemsPerPage); } createPagination() { const pages = []; const pageCount = this.pageCount(); const collection = [...this.collection]; for (let i = 0; i < pageCount; i++) { pages.push(collection.splice(0, this.itemsPerPage)); } return pages; } } -
gorkemozkan created this gist
Sep 16, 2023 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ class PaginationHelper { constructor(collection, itemsPerPage) { this.collection = collection; this.itemsPerPage = itemsPerPage; } itemCount() { return this.collection.length; } pageCount() { let pageCount = 0; const collection = this.#getCollection(); while (collection.length !== 0) { collection.splice(0, this.itemsPerPage); pageCount++; } return pageCount; } pageItemCount(pageIndex) { const pages = this.#createPagination(); return pages[pageIndex]?.length ?? -1; } pageIndex(itemIndex) { if (itemIndex < 0 || itemIndex >= this.itemCount()) { return -1; } return Math.floor(itemIndex / this.itemsPerPage); } #createPagination() { const pages = []; const pageCount = this.pageCount(); const collection = this.#getCollection(); for (let i = 0; i < pageCount; i++) { pages.push(collection.splice(0, this.itemsPerPage)); } return pages; } #getCollection() { return [...this.collection]; } }