diff --git a/packages/components/src/components/List/model/ReactTable.ts b/packages/components/src/components/List/model/ReactTable.ts index 3387059e6..ec9288c60 100644 --- a/packages/components/src/components/List/model/ReactTable.ts +++ b/packages/components/src/components/List/model/ReactTable.ts @@ -158,6 +158,10 @@ export class ReactTable { s.updateTableColumnDef(getOrCreateColumnDef(s.property)), ); + this.list.loader.staticDataProperties.forEach((property) => { + getOrCreateColumnDef(property); + }); + return Array.from(columnDefsMap.values()); } } diff --git a/packages/components/src/components/List/model/loading/IncrementalLoader.ts b/packages/components/src/components/List/model/loading/IncrementalLoader.ts index ec1a01f6e..38091133b 100644 --- a/packages/components/src/components/List/model/loading/IncrementalLoader.ts +++ b/packages/components/src/components/List/model/loading/IncrementalLoader.ts @@ -11,6 +11,7 @@ import { useEffect } from "react"; import { times } from "remeda"; import { IncrementalLoaderState } from "@/components/List/model/loading/IncrementalLoaderState"; import { hash } from "object-code"; +import type { PropertyName } from "@/components/List/model/types"; type AsyncResourceLoadingState = AsyncResource["state"]["value"]; @@ -23,6 +24,7 @@ export class IncrementalLoader { public readonly manualFiltering: boolean; public readonly manualPagination: boolean; public readonly loaderState: IncrementalLoaderState; + public readonly staticDataProperties: PropertyName[] = []; private constructor(list: List, shape: IncrementalLoaderShape = {}) { const { source } = shape; @@ -52,6 +54,8 @@ export class IncrementalLoader { this.manualSorting = manualSorting ?? this.manualPagination; this.list.filters.forEach((f) => f.onFilterUpdated(() => this.reset())); this.list.search?.onUpdated(() => this.reset()); + + this.initStaticDataProperties(); } public static useNew( @@ -61,6 +65,27 @@ export class IncrementalLoader { return new IncrementalLoader(list, shape); } + private initStaticDataProperties() { + const addPropertiesOfDataEntry = (data: unknown) => { + if (typeof data !== "object" || data === null) { + return; + } + + (Object.keys(data) as PropertyName[]) + .filter((p) => !this.staticDataProperties.includes(p)) + .forEach((p) => { + this.staticDataProperties.push(p); + }); + }; + + if ("staticData" in this.dataSource) { + this.dataSource.staticData + // collect properties from just the first 100 items + .slice(0, 100) + .forEach(addPropertiesOfDataEntry); + } + } + private reset(): void { this.loaderState.reset(); }