From 90b067ded3cfb00777806651dde4f3bce7685962 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sun, 20 Apr 2025 15:30:40 -0700 Subject: [PATCH] docs(data-table): improve docs --- docs/src/pages/components/DataTable.svx | 145 +++++++++--------- .../DataTableProgrammaticSorting.svelte | 65 ++++---- 2 files changed, 108 insertions(+), 102 deletions(-) diff --git a/docs/src/pages/components/DataTable.svx b/docs/src/pages/components/DataTable.svx index 70c758e3..c3eb1c59 100644 --- a/docs/src/pages/components/DataTable.svx +++ b/docs/src/pages/components/DataTable.svx @@ -8,21 +8,20 @@ components: ["DataTable", "Pagination","Toolbar", "ToolbarContent", "ToolbarSear import Preview from "../../components/Preview.svelte"; -`DataTable` is keyed for performance reasons. +`DataTable` displays structured data in a tabular format. Use it to present large datasets with features like sorting, filtering, pagination, and row selection. -
Every headers object must have a unique "key" property.
-
- - -
Every rows object must have a unique "id" property.
+
+ This component is keyed for performance. + + Every headers object must have a unique "key" property. +
Every rows object must have a unique "id" property.
+
## Default -The key value in `headers` corresponds to the key value defined in `rows`. - -For example, the header key `"name"` will use the value of `rows[index].name`. +Create a basic table by providing `headers` and `rows` data. Match the `key` in headers with the corresponding property in rows.
Custom column widths do not work with a sticky header.
@@ -340,9 +337,7 @@ A [table-layout: fixed](https://developer.mozilla.org/en-US/docs/Web/CSS/table-l ## Sticky header -Set `stickyHeader` to `true` for the header to be fixed in place. - -A maximum height will applied to the datatable to force a scrollbar. +Set `stickyHeader` to `true` to fix the header in place. This adds a maximum height to force scrolling. ## Filterable (custom) -`shouldFilterRows` also accepts a function and passes it the current row and search value. It expects the function to return a boolean. +Pass a function to `shouldFilterRows` to implement custom filtering logic. ## Zebra stripes +Set `zebra` to `true` to add alternating row colors. + ## Sortable with custom display and sort methods +Use `display` and `sort` functions in header objects to customize cell rendering and sorting. + ## Empty column with overflow menu -Some use cases require an empty column in the table body without a corresponding table header. - -For an object in the `headers` array, set `empty` to `true` to render an empty column. - -In the following example, each row in the sortable data table has an overflow menu. There isn't a separate, useless table header column for the overflow menu. +Set `empty: true` in a header object to create an empty column. Use this for overflow menus without a header. ## Selectable rows (checkbox) -Set `selectable` to `true` for rows to be multi-selectable. - -Bind to `selectedRowIds` to get the ids of the selected rows. - -To customize the `input` name for the checkbox, use the `inputName` prop. +Set `selectable` to `true` for multi-select functionality. Bind to `selectedRowIds` to track selections. Use `inputName` to customize checkbox names. ## Batch selection -To enable batch selection, set `batchSelection` to `true`. - -This checkbox is used to select all rows. It enters an indeterminate state when some rows are selected. +Set `batchSelection` to `true` to add a checkbox for selecting all rows. The checkbox shows an indeterminate state when some rows are selected. ## Batch selection with initial selected rows -Use the `selectedRowIds` prop to specify which rows should be selected. +Use `selectedRowIds` to specify initially selected rows. ## Batch selection with batch actions toolbar +Add a toolbar for batch actions when rows are selected. + ## Batch selection with controlled toolbar -By default, `ToolbarBatchActions` is activated if one or more rows is selected. Clicking "Cancel" will deactivate it. - -Use the `active` prop to control the toolbar. Note that it will still activate if one or more rows are selected. - -You can prevent the default "Cancel" behavior in the dispatched `on:cancel` event. +Control the batch actions toolbar with the `active` prop. Prevent default cancel behavior in the `on:cancel` event. ## Selectable rows (radio) -Set `radio` to `true` for only one row to be selected at a time. - -Bind to `selectedRowIds` to get the ids of the selected rows. Because it's radio selection, `selectedRowIds` will only contain one id. - -To customize the `input` name for the radio button, use the `inputName` prop. +Set `radio` to `true` for single-row selection. Bind to `selectedRowIds` to track the selected row. Use `inputName` to customize radio button names. ## Non-selectable rows -Use `nonSelectableRowIds` to specify the ids for rows that should not be selectable. +Use `nonSelectableRowIds` to prevent selection of specific rows. ## Expandable rows -Set `expandable` to `true` for rows to be expandable. +Set `expandable` to `true` to make rows expandable. Use the `expanded-row` slot to customize expanded content. ## Expandable (zebra styles) +Combine expandable rows with zebra striping. + ## Expandable (compact size) +Set `size="compact"` for expandable rows with minimal height. + ## Skeleton +Use `DataTableSkeleton` to show a loading state. + ## Skeleton with headers, row count +Specify headers and row count for the skeleton. + ## 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`. +Pass header objects to customize the skeleton. ## Skeleton with empty header -Pass an object with `"empty"` set to `true` to render an empty table header column. +Add an empty header column with `empty: true`. ## Skeleton without header, toolbar +Hide the header and toolbar in the skeleton. + ## Skeleton (tall size) +Set `size="tall"` for a taller skeleton. + ## Skeleton (short size) +Set `size="short"` for a shorter skeleton. + ## Skeleton (compact size) +Set `size="compact"` for a minimal skeleton. + \ No newline at end of file diff --git a/docs/src/pages/framed/DataTable/DataTableProgrammaticSorting.svelte b/docs/src/pages/framed/DataTable/DataTableProgrammaticSorting.svelte index 785487c7..998856dc 100644 --- a/docs/src/pages/framed/DataTable/DataTableProgrammaticSorting.svelte +++ b/docs/src/pages/framed/DataTable/DataTableProgrammaticSorting.svelte @@ -8,37 +8,40 @@ $: console.log("sortDirection", sortDirection); - - - - - +
+ + + +