From 19c659fa165abdb518bf988066dd912e0d086fac Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 24 Mar 2021 19:06:02 +0000 Subject: [PATCH] Add setting for table row count and improve height calculation --- packages/standard-components/manifest.json | 6 ++ .../src/table/Table.svelte | 97 +++++++++++-------- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/packages/standard-components/manifest.json b/packages/standard-components/manifest.json index e35a3c8caa..5c110d2d12 100644 --- a/packages/standard-components/manifest.json +++ b/packages/standard-components/manifest.json @@ -1533,6 +1533,12 @@ "key": "showAutoColumns", "defaultValue": false }, + { + "type": "number", + "label": "Row Count", + "key": "rowCount", + "defaultValue": 8 + }, { "type": "select", "label": "Theme", diff --git a/packages/standard-components/src/table/Table.svelte b/packages/standard-components/src/table/Table.svelte index 8df8c06e34..24eb2d121f 100644 --- a/packages/standard-components/src/table/Table.svelte +++ b/packages/standard-components/src/table/Table.svelte @@ -8,7 +8,7 @@ export let dataProvider export let columns export let showAutoColumns - export let rowCount = 8 + export let rowCount const component = getContext("component") const { styleable } = getContext("sdk") @@ -16,12 +16,26 @@ let sortColumn let sortOrder + $: styles = makeStyles($component.styles, rowCount) $: rows = dataProvider?.rows ?? [] $: sortedRows = sortRows(rows, sortColumn, sortOrder) $: loaded = dataProvider?.loaded ?? false $: schema = dataProvider?.schema ?? {} $: fields = getFields(schema, columns, showAutoColumns) + const makeStyles = (styles, rowCount) => { + if (!rowCount) { + return styles + } + return { + ...styles, + normal: { + ...styles.normal, + height: `${37 + rowCount * 56}px`, + }, + } + } + const sortRows = (rows, sortColumn, sortOrder) => { if (!sortColumn || !sortOrder) { return rows @@ -52,7 +66,6 @@ } let columns = [] Object.entries(schema).forEach(([field, fieldSchema]) => { - console.log(fieldSchema) if (showAutoColumns || !fieldSchema?.autocolumn) { columns.push(field) } @@ -61,50 +74,48 @@ } -
-
- - - +
+
+ + + {#each fields as field} + + {/each} + + + + {#each sortedRows as row} + {#each fields as field} - {/each} - - - {#each sortedRows as row} - - {#each fields as field} - - {/each} - - {/each} - -
sortBy(field)}> +
+ {schema[field]?.name} + +
+
sortBy(field)}> -
- {schema[field]?.name} - +
+
+
- +
-
- -
-
-
+ {/each} + +