From d1f2861fd5ed1388a622c445e676092d23017fe6 Mon Sep 17 00:00:00 2001 From: DanyLE Date: Thu, 2 Feb 2023 21:54:47 +0100 Subject: [PATCH] ListView: add API to scroll the list to top/bottom --- d.ts/antos.d.ts | 26 +++++++++++++++++++++++++- src/core/tags/GridViewTag.ts | 21 ++++++++++++++++++++- src/core/tags/ListViewTag.ts | 20 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/d.ts/antos.d.ts b/d.ts/antos.d.ts index 7960d26..c858f80 100644 --- a/d.ts/antos.d.ts +++ b/d.ts/antos.d.ts @@ -4744,6 +4744,18 @@ declare namespace OS { * @memberof ListViewTag */ protected dropoff(e: any): void; + /** + * Scroll the list view to bottom + * + * @memberof ListViewTag + */ + scroll_to_bottom(): void; + /** + * Scroll the list view to top + * + * @memberof ListViewTag + */ + scroll_to_top(): void; /** * calibrate the list layout * @@ -6316,13 +6328,25 @@ declare namespace OS { * @memberof GridViewTag */ delete(row: GridRowTag): void; + /** + * Scroll the grid view to bottom + * + * @memberof GridViewTag + */ + scroll_to_bottom(): void; + /** + * Scroll the grid view to top + * + * @memberof GridViewTag + */ + scroll_to_top(): void; /** * Push a row to the grid * * @param {GenericObject[]} row list of cell data * @param {boolean} flag indicates where the row is add to beginning or end * of the row - * @memberof GridViewTags + * @memberof GridViewTag */ push(row: GenericObject[], flag: boolean): void; /** diff --git a/src/core/tags/GridViewTag.ts b/src/core/tags/GridViewTag.ts index 0221948..84fca7a 100644 --- a/src/core/tags/GridViewTag.ts +++ b/src/core/tags/GridViewTag.ts @@ -869,6 +869,25 @@ namespace OS { } $(row).remove(); } + /** + * Scroll the grid view to bottom + * + * @memberof GridViewTag + */ + scroll_to_bottom() + { + this.refs.container.scrollTo({ top: this.refs.container.scrollHeight, behavior: 'smooth' }) + } + + /** + * Scroll the grid view to top + * + * @memberof GridViewTag + */ + scroll_to_top() + { + this.refs.container.scrollTo({ top: 0, behavior: 'smooth' }); + } /** * Push a row to the grid @@ -876,7 +895,7 @@ namespace OS { * @param {GenericObject[]} row list of cell data * @param {boolean} flag indicates where the row is add to beginning or end * of the row - * @memberof GridViewTags + * @memberof GridViewTag */ push(row: GenericObject[], flag: boolean): void { const rowel = $("").css( diff --git a/src/core/tags/ListViewTag.ts b/src/core/tags/ListViewTag.ts index 4eb16b8..be576a5 100644 --- a/src/core/tags/ListViewTag.ts +++ b/src/core/tags/ListViewTag.ts @@ -1346,6 +1346,26 @@ namespace OS { } } + /** + * Scroll the list view to bottom + * + * @memberof ListViewTag + */ + scroll_to_bottom() + { + this.refs.mlist.scrollTo({ top: this.refs.mlist.scrollHeight, behavior: 'smooth' }) + } + + /** + * Scroll the list view to top + * + * @memberof ListViewTag + */ + scroll_to_top() + { + this.refs.mlist.scrollTo({ top: 0, behavior: 'smooth' }); + } + /** * calibrate the list layout *