import { Meta, Canvas } from '@storybook/blocks'; import * as TableStories from './Table.stories.svelte'; # Table The `Table` component presents data as a table that you can make searchable, filtereable, sortable, or paginated. ```svelte ``` ## Text elements Set the `title`, `dek`, `notes` and `source` options to add supporting metadata above and below the table. ```svelte
``` ## Truncated When your table has 10 or more rows, consider clipping it by setting the `truncated` option. When it is enabled, the table is clipped and readers must click a button below the table to see all rows. By default, this configuration will limit the table to 5 records. Change the cutoff point by adjusting the `truncateLength` option. This is a good option for simple tables with between 10 and 30 rows. It works best when the table doesn't require interactivity. ```svelte
``` ## Paginated When your table has many rows, you should consider breaking it up into pages by setting `paginated` to `true`. When it is enabled, readers can leaf through the data using a set of buttons below the table. By default, there are 25 records per page. Change the number by adjusting the `pageSize` option. This is a good option when publishing large tables for readers to explore. It works well with interactive features like searching and filters. ```svelte
``` ## Search bar Allow users to search the table by setting the optional `searchable` option to `true`. Modify the default text that appears in the box by setting `searchPlaceholder` to a different placeholder text. ```svelte
``` ## Filter Allow users to filter the table by providing one of the attributes as the `filterField`. This works best with categorical columns. Set `filterLabel` to make the category name more readable. For example, if the column is `Region`, set `filterLabel` to `regions` or `regions of the world`. ```svelte
``` ## Search and filter Feel free to both search and filter. ```svelte
``` ``` ## Sort Allow users to sort the table by setting `sortable` to `true`. Specify the starting order by setting `sortField` to a column name and `sortDirection` to `ascending` or `descending`. By default, all fields are sortable. If you'd like to limit the columns where sorting is allowed, provide a list to the `sortableFields` option. ```svelte
``` ## Format Format column values by supplying functions keyed to field names with the `fieldFormatters` option. Columns are still sorted using the raw, underlying values. Among other things, this feature can be used to provide a unit of measurement, such as `$` or `%`, with numeric fields. ```svelte
```