diff --git a/COMPONENT_INDEX.md b/COMPONENT_INDEX.md index 2da9656f..8ff71575 100644 --- a/COMPONENT_INDEX.md +++ b/COMPONENT_INDEX.md @@ -779,7 +779,10 @@ export interface DataTableNonEmptyHeader { export type DataTableHeader = DataTableNonEmptyHeader | DataTableEmptyHeader; -export type DataTableRow = Record; +export interface DataTableRow { + id: any; + [key: string]: DataTableValue; +} export type DataTableRowId = string; @@ -835,15 +838,15 @@ export interface DataTableCell { ### Props -| Prop name | Kind | Reactive | Type | Default value | Description | -| :---------- | :--------------- | :------- | :-------------------------------------------------- | ------------------ | ------------------------------------------------------------------------------- | -| columns | let | No | number | 5 | Specify the number of columns | -| rows | let | No | number | 5 | Specify the number of rows | -| size | let | No | "compact" | "short" | "tall" | -- | Set the size of the data table | -| zebra | let | No | boolean | false | Set to `true` to apply zebra styles to the datatable rows | -| showHeader | let | No | boolean | true | Set to `false` to hide the header | -| headers | let | No | string[] | [] | Set the column headers
If `headers` has one more items, `count` is ignored | -| showToolbar | let | No | boolean | true | Set to `false` to hide the toolbar | +| Prop name | Kind | Reactive | Type | Default value | Description | +| :---------- | :--------------- | :------- | :------------------------------------------------------ | ------------------ | -------------------------------------------------------------------------------------------- | +| columns | let | No | number | 5 | Specify the number of columns
Superseded by `headers` if `headers` is a non-empty array | +| rows | let | No | number | 5 | Specify the number of rows | +| size | let | No | "compact" | "short" | "tall" | -- | Set the size of the data table | +| zebra | let | No | boolean | false | Set to `true` to apply zebra styles to the datatable rows | +| showHeader | let | No | boolean | true | Set to `false` to hide the header | +| headers | let | No | string[] | Partial[] | [] | Set the column headers
Supersedes `columns` if value is a non-empty array | +| showToolbar | let | No | boolean | true | Set to `false` to hide the toolbar | ### Slots diff --git a/docs/src/COMPONENT_API.json b/docs/src/COMPONENT_API.json index 79579b29..7a1cdbea 100644 --- a/docs/src/COMPONENT_API.json +++ b/docs/src/COMPONENT_API.json @@ -2655,9 +2655,9 @@ "ts": "type DataTableHeader = DataTableNonEmptyHeader | DataTableEmptyHeader" }, { - "type": "Record", + "type": "{ id: any; [key: string]: DataTableValue; }", "name": "DataTableRow", - "ts": "type DataTableRow = Record" + "ts": "interface DataTableRow { id: any; [key: string]: DataTableValue; }" }, { "type": "string", @@ -3281,7 +3281,7 @@ { "name": "columns", "kind": "let", - "description": "Specify the number of columns", + "description": "Specify the number of columns\nSuperseded by `headers` if `headers` is a non-empty array", "type": "number", "value": "5", "isFunction": false, @@ -3330,8 +3330,8 @@ { "name": "headers", "kind": "let", - "description": "Set the column headers\nIf `headers` has one more items, `count` is ignored", - "type": "string[]", + "description": "Set the column headers\nSupersedes `columns` if value is a non-empty array", + "type": "string[] | Partial[]", "value": "[]", "isFunction": false, "constant": false, @@ -3356,7 +3356,11 @@ { "type": "forwarded", "name": "mouseleave", "element": "table" } ], "typedefs": [], - "rest_props": { "type": "Element", "name": "table" } + "rest_props": { "type": "Element", "name": "table" }, + "extends": { + "interface": "DataTableHeader", + "import": "\"../DataTable/DataTable\"" + } }, { "moduleName": "DatePicker", diff --git a/docs/src/pages/components/DataTable.svx b/docs/src/pages/components/DataTable.svx index 8998770a..2dc2889f 100644 --- a/docs/src/pages/components/DataTable.svx +++ b/docs/src/pages/components/DataTable.svx @@ -10,6 +10,8 @@ components: ["DataTable", "Toolbar", "ToolbarContent", "ToolbarSearch", "Toolbar ### Default +The `DataTable` is keyed for both rendering and sorting. You must define a "key" value per object in the `headers` property and an "id" value in `rows`. + +### Skeleton with object headers + +`headers` can also be an array of objects. The type is the same as the `headers` prop type used in `DataTable`. + + + ### Skeleton without header, toolbar diff --git a/src/DataTable/DataTable.svelte b/src/DataTable/DataTable.svelte index 5efe3212..a932d26f 100644 --- a/src/DataTable/DataTable.svelte +++ b/src/DataTable/DataTable.svelte @@ -5,7 +5,7 @@ * @typedef {{ key: DataTableKey; empty: boolean; display?: (item: Value) => DataTableValue; sort?: (a: DataTableValue, b: DataTableValue) => (0 | -1 | 1); columnMenu?: boolean; }} DataTableEmptyHeader * @typedef {{ key: DataTableKey; value: DataTableValue; display?: (item: Value) => DataTableValue; sort?: (a: DataTableValue, b: DataTableValue) => (0 | -1 | 1); columnMenu?: boolean; }} DataTableNonEmptyHeader * @typedef {DataTableNonEmptyHeader | DataTableEmptyHeader} DataTableHeader - * @typedef {Record} DataTableRow + * @typedef {{ id: any; [key: string]: DataTableValue; }} DataTableRow * @typedef {string} DataTableRowId * @typedef {{ key: DataTableKey; value: DataTableValue; }} DataTableCell * @slot {{ row: DataTableRow; }} expanded-row diff --git a/src/DataTableSkeleton/DataTableSkeleton.svelte b/src/DataTableSkeleton/DataTableSkeleton.svelte index 854714ce..2ee4ade3 100644 --- a/src/DataTableSkeleton/DataTableSkeleton.svelte +++ b/src/DataTableSkeleton/DataTableSkeleton.svelte @@ -1,5 +1,10 @@