From 0f56ed3c95d738d3c1e7e0e8ee23d1a926462a18 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 13 Apr 2021 15:10:27 +0100 Subject: [PATCH] Fix scroll state not resetting --- packages/bbui/src/Table/Table.svelte | 223 ++++++++++++++------------- 1 file changed, 117 insertions(+), 106 deletions(-) diff --git a/packages/bbui/src/Table/Table.svelte b/packages/bbui/src/Table/Table.svelte index 9697ce86f9..a9bb50fd9d 100644 --- a/packages/bbui/src/Table/Table.svelte +++ b/packages/bbui/src/Table/Table.svelte @@ -50,6 +50,15 @@ rows.length ) + // Reset state when data chanegs + $: data.length, reset() + const reset = () => { + nextScrollTop = 0 + scrollTop = 0 + clearTimeout(timeout) + timeout = null + } + const getVisibleRowCount = (loaded, height, allRows, rowCount) => { if (!loaded) { return rowCount || 0 @@ -175,128 +184,129 @@ } -
+
{#if !loaded}
{:else} -
- - {#if sortedRows?.length} - - - {#if showEditColumn} - - {/if} - {#each fields as field} - - {/each} - - - {/if} - +
+
+
-
- {editColumnTitle || ''} -
-
sortBy(schema[field])}> -
-
{getDisplayName(schema[field])}
- {#if schema[field]?.autocolumn} - - - - {/if} - {#if sortColumn === field} - - {/if} - {#if allowEditColumns && schema[field]?.editable !== false} - editColumn(e, field)}> - - - {/if} -
-
{#if sortedRows?.length} - {#each sortedRows as row, idx} - toggleSelectRow(row)} - class="spectrum-Table-row" - class:hidden={idx < firstVisibleRow || idx > lastVisibleRow}> - {#if idx >= firstVisibleRow && idx <= lastVisibleRow} - {#if showEditColumn} - - {/if} - {#each fields as field} - - {/each} + + + {#if showEditColumn} + {/if} + {#each fields as field} + + {/each} - {/each} - {:else} -
- - - -
No rows found
-
+ {/if} - -
-
- toggleSelectRow(row)} - onEdit={e => editRow(e, row)} - {allowSelectRows} - {allowEditRows} /> -
-
-
- - - -
-
+
+ {editColumnTitle || ''} +
+
sortBy(schema[field])}> +
+
{getDisplayName(schema[field])}
+ {#if schema[field]?.autocolumn} + + + + {/if} + {#if sortColumn === field} + + {/if} + {#if allowEditColumns && schema[field]?.editable !== false} + editColumn(e, field)}> + + + {/if} +
+
+ + {#if sortedRows?.length} + {#each sortedRows as row, idx} + toggleSelectRow(row)} + class="spectrum-Table-row" + class:hidden={idx < firstVisibleRow || idx > lastVisibleRow}> + {#if idx >= firstVisibleRow && idx <= lastVisibleRow} + {#if showEditColumn} + +
+ toggleSelectRow(row)} + onEdit={e => editRow(e, row)} + {allowSelectRows} + {allowEditRows} /> +
+ + {/if} + {#each fields as field} + +
+ + + +
+ + {/each} + {/if} + + {/each} + {:else} +
+ + + +
No rows found
+
+ {/if} + + +
{/if}