From 8b03c25512c6e5dad5c032505a4a24287f7df726 Mon Sep 17 00:00:00 2001 From: Vikas Awaghade <67629551+vikas-cldcvr@users.noreply.github.com> Date: Thu, 9 May 2024 12:08:33 +0530 Subject: [PATCH] FDS-667 infinite scroll bug fixed (#270) * FDS-667 infinite scroll bug fixed * FDS-667 search bar width fixed * FDS-667 search bar made stikcy --- packages/flow-table/CHANGELOG.md | 11 +++ packages/flow-table/package.json | 2 +- .../f-table-schema/f-table-schema-global.scss | 1 + .../f-table-schema/f-table-schema.scss | 6 +- .../f-table-schema/f-table-schema.ts | 76 +++++++++++++------ stories/flow-table/f-table-schema.stories.ts | 10 ++- 6 files changed, 78 insertions(+), 28 deletions(-) diff --git a/packages/flow-table/CHANGELOG.md b/packages/flow-table/CHANGELOG.md index 5f766b553..7feddce3e 100644 --- a/packages/flow-table/CHANGELOG.md +++ b/packages/flow-table/CHANGELOG.md @@ -2,6 +2,17 @@ # Change Log +## [2.4.3] - 2024-05-03 + +### Improvements + +- Made the search bar sticky. +- Implemented a loader for infinite scroll. + +### Bug Fixes + +- `f-table-schema` infinie scroll issue fixed. + ## [2.4.2] - 2024-03-20 ### Bug Fixes diff --git a/packages/flow-table/package.json b/packages/flow-table/package.json index 075f44568..0c34cd596 100644 --- a/packages/flow-table/package.json +++ b/packages/flow-table/package.json @@ -1,6 +1,6 @@ { "name": "@ollion/flow-table", - "version": "2.4.2", + "version": "2.4.3", "description": "Table component for flow library", "module": "dist/flow-table.es.js", "main": "dist/flow-table.cjs.js", diff --git a/packages/flow-table/src/components/f-table-schema/f-table-schema-global.scss b/packages/flow-table/src/components/f-table-schema/f-table-schema-global.scss index 0ae48cd55..b2bb1e90a 100644 --- a/packages/flow-table/src/components/f-table-schema/f-table-schema-global.scss +++ b/packages/flow-table/src/components/f-table-schema/f-table-schema-global.scss @@ -6,6 +6,7 @@ f-table-schema { max-width: 100%; display: flex; overflow: auto; + flex-direction: column; } f-div[direction="column"] { diff --git a/packages/flow-table/src/components/f-table-schema/f-table-schema.scss b/packages/flow-table/src/components/f-table-schema/f-table-schema.scss index 162baeb54..34d1894d7 100644 --- a/packages/flow-table/src/components/f-table-schema/f-table-schema.scss +++ b/packages/flow-table/src/components/f-table-schema/f-table-schema.scss @@ -1,9 +1,13 @@ +@import "../../../../flow-core/src/mixins/scss/mixins"; + :host { f-table { height: fit-content; width: 100%; } > div.f-table-schema-wrapper { - flex: 1 1 auto; + flex: 1 1; + overflow: auto; + @include scrollbar(); } } diff --git a/packages/flow-table/src/components/f-table-schema/f-table-schema.ts b/packages/flow-table/src/components/f-table-schema/f-table-schema.ts index 1d4e8be05..60a564414 100644 --- a/packages/flow-table/src/components/f-table-schema/f-table-schema.ts +++ b/packages/flow-table/src/components/f-table-schema/f-table-schema.ts @@ -188,9 +188,15 @@ export class FTableSchema extends FRoot { @query("f-div.load-more") loadMoreButton?: FDiv; + @query("#pagination-loader") + paginationLoader!: FDiv; + @query("#f-table-element") tableElement?: FTable; + @query(".f-table-schema-wrapper") + fTableWrapper!: HTMLDivElement; + nextEmitted = false; get max() { @@ -431,20 +437,24 @@ export class FTableSchema extends FRoot { return html` Warning: The 'data' property is required.`; } return html` + + ${this.showSearchBar + ? html` + + ` + : nothing} +
- - ${this.showSearchBar - ? html` - - ` - : nothing} - ${this.header} ${this.rowsHtml} ${this.noDataTemplate} + @@ -467,11 +478,35 @@ export class FTableSchema extends FRoot { protected updated(changedProperties: PropertyValueMap | Map): void { super.updated(changedProperties); - this.onscroll = () => { - if (this.scrollTop + this.offsetHeight >= this.scrollHeight) { - this.paginate(); + const handleLoadMoreButton = () => { + if ( + this.fTableWrapper.scrollHeight === this.fTableWrapper.offsetHeight && + this.filteredRows.length < this.searchedRows.length + ) { + this.loadMoreButton?.style.removeProperty("display"); + } else if (this.loadMoreButton) { + this.loadMoreButton.style.display = "none"; + } + }; + + this.fTableWrapper.onscroll = () => { + handleLoadMoreButton(); + + // offset difference added , instead of exact equal + if ( + this.fTableWrapper.scrollHeight - + (this.fTableWrapper.scrollTop + this.fTableWrapper.offsetHeight) < + 24 + ) { + if (this.filteredRows.length !== this.searchedRows.length) { + this.paginationLoader.style.width = this.offsetWidth + "px"; + this.paginationLoader.style.display = "flex"; + } + // settimeout added to display above loader first + setTimeout(() => this.paginate()); } if (this.filteredRows.length === this.searchedRows.length && !this.nextEmitted) { + this.paginationLoader.style.display = "none"; setTimeout(() => { this.nextEmitted = true; const toggle = new CustomEvent("next", { @@ -484,14 +519,7 @@ export class FTableSchema extends FRoot { } }; void this.updateComplete.then(async () => { - if ( - this.scrollHeight === this.offsetHeight && - this.filteredRows.length < this.searchedRows.length - ) { - this.loadMoreButton?.style.removeProperty("display"); - } else if (this.loadMoreButton) { - this.loadMoreButton.style.display = "none"; - } + handleLoadMoreButton(); if (this.tableElement) { await this.tableElement.updateHeaderSelectionCheckboxState(); } diff --git a/stories/flow-table/f-table-schema.stories.ts b/stories/flow-table/f-table-schema.stories.ts index 01629393d..d59cd2374 100644 --- a/stories/flow-table/f-table-schema.stories.ts +++ b/stories/flow-table/f-table-schema.stories.ts @@ -48,7 +48,13 @@ export const Playground = { - + 'f-table-schema' supports all properties and events of 'f-table'