--- components: ["DataTable", "Pagination","Toolbar", "ToolbarContent", "ToolbarSearch", "ToolbarMenu", "ToolbarMenuItem", "ToolbarBatchActions"] --- `DataTable` is keyed for performance reasons.
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`. ## Slotted cells Use the `"cell"` slot to control the display value per table cell. Individual row and cell data are provided through the `let:row` and `let:cell` directives. The slot name for the table header cells is `"cell-header"`. {#if header.key === 'port'} {header.value} (network) {:else} {header.value} {/if} {#if cell.key === 'rule' && cell.value === 'Round robin'} {cell.value} {:else} {cell.value} {/if} ## With title, description ## Slottable title, description The `title` and `description` props are slottable. Load balancers Your organization's active load balancers. ## Static width Set `useStaticWidth` to `true` to render the table with a width of "auto" instead of "100%". ## Custom column widths Specify a `width` or `minWidth` property in the `headers` object to customize the width of each column. A [table-layout: fixed](https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout#values) rule will be applied to the `table` element when using custom widths.
Custom column widths do not work with a sticky header.
## 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. ({ id: i, name: "Load Balancer " + (i + 1), protocol: "HTTP", port: i % 3 ? (i % 2 ? 3000 : 80) : 443, rule: i % 3 ? "Round robin" : "DNS delegation", }))} /> ## With toolbar Restart all API documentation Stop all ## With toolbar (small size) Restart all API documentation Stop all ## Filterable By default, `ToolbarSearch` will not filter `DataTable` rows. Set `shouldFilterRows` to `true` to enable client-side filtering. The default filtering performs a basic string comparison on cell values that are of a string or a number type. To use filtering with pagination, bind to the `filteredRowIds` prop and pass its length to `totalItems` in `Pagination`. Note that in-memory filtering is not optimal for large data sets, where you might consider using server-side search. ## Filterable (custom) `shouldFilterRows` also accepts a function and passes it the current row and search value. It expects the function to return a boolean. ## Zebra stripes ## Tall rows ## Medium rows ## Short rows ## Compact rows ## Sortable Set `sortable` to `true` to enable table column sorting. To disable sorting on a specific column, set `sort` to `false` in the header object passed to the `headers` prop. In the example below, the "Protocol" column is not sortable. ## Sortable with pagination For pagination, bind to the `pageSize` and `page` props of `Pagination` and pass their values to `DataTable`. ## Sortable with custom display and sort methods cost + " €" }, { key: "expireDate", value: "Expire date", display: (date) => new Date(date).toLocaleString(), sort: (a, b) => new Date(a) - new Date(b), }, ]}" rows="{[ { id: "a", name: "Load Balancer 3", protocol: "HTTP", port: 3000, cost: 100, expireDate: "2020-10-21", }, { id: "b", name: "Load Balancer 1", protocol: "HTTP", port: 443, cost: 200, expireDate: "2020-09-10", }, { id: "c", name: "Load Balancer 2", protocol: "HTTP", port: 80, cost: 150, expireDate: "2020-11-24", }, { id: "d", name: "Load Balancer 6", protocol: "HTTP", port: 3000, cost: 250, expireDate: "2020-12-01", }, { id: "e", name: "Load Balancer 4", protocol: "HTTP", port: 443, cost: 550, expireDate: "2021-03-21", }, { id: "f", name: "Load Balancer 5", protocol: "HTTP", port: 80, cost: 400, expireDate: "2020-11-14", }, ]}" /> ## Sortable with nested object values cost + " €" }, { key: "expireDate", value: "Expire date", display: (date) => new Date(date).toLocaleString(), sort: (a, b) => new Date(a) - new Date(b), }, ]}" rows="{[ { id: "a", name: "Load Balancer 3", network: { protocol: "HTTP", port: 3000, }, cost: 100, expireDate: "2020-10-21", }, { id: "b", name: "Load Balancer 1", network: { protocol: "HTTP", port: 443, }, cost: 200, expireDate: "2020-09-10", }, { id: "c", name: "Load Balancer 2", network: { protocol: "HTTP", port: 80, }, cost: 150, expireDate: "2020-11-24", }, { id: "d", name: "Load Balancer 6", network: { protocol: "HTTP", port: 3000, }, cost: 250, expireDate: "2020-12-01", }, { id: "e", name: "Load Balancer 4", network: { protocol: "HTTP", port: 443, }, cost: 550, expireDate: "2021-03-21", }, { id: "f", name: "Load Balancer 5", network: { protocol: "HTTP", port: 80, }, cost: 400, expireDate: "2020-11-14", }, ]}" /> ## Programmatic sorting Use the reactive `sortKey` and `sortDirection` props for programmatic sorting. By default, the table is not sorted by a specific key. The `sortKey` value must be a valid `key` specified in the `headers` object. Possible values for `sortDirection` include `"none"` or `"ascending"` or `"descending"`. Setting `sortKey` to `null` and `sortDirection` to `"none"` should reset the table rows to their initial order. ## 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. ## Selectable rows (checkbox) Set `selectable` to `true` for rows to be multi-selectable. ## Batch selection ## Batch selection with initial selected rows Use the `selectedRowIds` prop to specify which rows should be selected. ## Batch selection with batch actions toolbar ## 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 also prevent the default "Cancel" behavior in the dispatched `on:cancel` event. ## Selectable rows (radio) Set `radio` to `true` for only one row to be selected at a time. ## Non-selectable rows Use `nonSelectableRowIds` to specify the ids for rows that should not be selectable. ## Expandable rows Set `expandable` to `true` for rows to be expandable.
{JSON.stringify(row, null, 2)}
## Non-expandable rows Use `nonExpandableRowIds` to specify the ids for rows that should not be expandable. ## Expandable (zebra styles) ## Expandable (compact size)
{JSON.stringify(row, null, 2)}
## Expandable (short size)
{JSON.stringify(row, null, 2)}
## Expandable (tall size)
{JSON.stringify(row, null, 2)}
## Batch expansion Set `batchExpansion` to `true` for the ability to expand and collapse all rows at once.
{JSON.stringify(row, null, 2)}
## Expandable and selectable rows The `batchExpansion` and `batchSelection` props can be used together. ## Skeleton ## Skeleton with headers, row count ## 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 with empty header Pass an object with `"empty"` set to `true` to render an empty table header column. ## Skeleton without header, toolbar ## Skeleton (tall size) ## Skeleton (short size) ## Skeleton (compact size)