From cdaf2dfcd4f515f58a2e87959ab6484cbd658e51 Mon Sep 17 00:00:00 2001 From: maks Date: Thu, 1 Aug 2024 14:45:29 +0100 Subject: [PATCH] #514 - fixed row size init --- src/components/revoGrid/revo-grid.tsx | 32 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/components/revoGrid/revo-grid.tsx b/src/components/revoGrid/revo-grid.tsx index 57af0a55..cef92030 100644 --- a/src/components/revoGrid/revo-grid.tsx +++ b/src/components/revoGrid/revo-grid.tsx @@ -11,7 +11,6 @@ import { VNode, Host, } from '@stencil/core'; -import each from 'lodash/each'; import ColumnDataProvider, { ColumnCollection, @@ -1005,7 +1004,7 @@ export class RevoGridComponent { @Watch('rowSize') rowSizeChanged(s: number) { // clear existing data this.dimensionProvider.setSettings({ originItemSize: s }, 'rgRow'); - this.rowDefChanged(this.rowDefinitions, this.rowDefinitions); + this.rowDefChanged(this.rowDefinitions, this.rowDefinitions, 'rowSize', true); } @Watch('theme') themeChanged( @@ -1106,6 +1105,8 @@ export class RevoGridComponent { @Watch('rowDefinitions') rowDefChanged( after: RowDefinition[], before?: RowDefinition[], + _watchName?: string, + forceUpdate = true, ) { const { detail: { vals: newVal, oldVals: oldVal }, @@ -1119,19 +1120,26 @@ export class RevoGridComponent { if (oldVal) { const remove = rowDefinitionRemoveByType(oldVal); // clear all old data and drop sizes - each(remove, (_, t: DimensionRows) => { - this.dimensionProvider.clearSize( - t, - this.dataProvider.stores[t].store.get('source').length, - ); - }); + for (const t in remove) { + if (remove.hasOwnProperty(t)) { + const type = t as DimensionRows; + const store = this.dataProvider.stores[type]; + const sourceLength = store.store.get('source').length; + this.dimensionProvider.clearSize(type, sourceLength); + } + } } if (!newVal.length) { - return; + if (forceUpdate) { + this.dimensionProvider.setCustomSizes('rgRow', {}); + } else { + return; + } } - each(newRows, (r, k: DimensionRows) => - this.dimensionProvider.setCustomSizes(k, r.sizes || {}), - ); + Object.entries(newRows).forEach(([k, r]) => { + const type = k as DimensionRows; + this.dimensionProvider.setCustomSizes(type, r.sizes || {}); + }); } @Watch('trimmedRows') trimmedRowsChanged(