mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-19 11:59:34 +00:00
822 lines
16 KiB
Text
822 lines
16 KiB
Text
---
|
|
components: ["DataTable", "Toolbar", "ToolbarContent", "ToolbarSearch", "ToolbarBatchActions"]
|
|
---
|
|
|
|
<script>
|
|
import { DataTable, DataTableSkeleton, Toolbar, ToolbarContent, ToolbarSearch, Button, Link } from "carbon-components-svelte";
|
|
import Launch16 from "carbon-icons-svelte/lib/Launch16";
|
|
import Preview from "../../components/Preview.svelte";
|
|
</script>
|
|
|
|
### Default
|
|
|
|
<DataTable
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
/>
|
|
|
|
### 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"`.
|
|
|
|
<DataTable
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
>
|
|
<span slot="cell-header" let:header>
|
|
{#if header.key === 'port'}
|
|
{header.value} (network)
|
|
{:else}
|
|
{header.value}
|
|
{/if}
|
|
</span>
|
|
<span slot="cell" let:row let:cell>
|
|
{#if cell.key === 'rule' && cell.value === 'Round robin'}
|
|
<Link inline href="https://en.wikipedia.org/wiki/Round-robin_DNS" target="_blank">{cell.value} <Launch16 /></Link>
|
|
{:else}
|
|
{cell.value}
|
|
{/if}
|
|
</span>
|
|
</DataTable>
|
|
|
|
### With title, description
|
|
|
|
<DataTable title="Load balancers" description="Your organization's active load balancers."
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
/>
|
|
|
|
### With custom display and sort methods
|
|
|
|
<DataTable sortable title="Load balancers" description="Your organization's active load balancers."
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "cost", value: "Cost", display: (cost) => cost + " €" },
|
|
{
|
|
key: "expireDate",
|
|
value: "Expire date",
|
|
display: (date) => new Date(date).toLocaleString(),
|
|
sort: (a, b) => (new Date(a) <= new Date(b) ? -1 : 1),
|
|
},
|
|
]}"
|
|
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",
|
|
},
|
|
]}"
|
|
/>
|
|
|
|
### With toolbar
|
|
|
|
<DataTable title="Load balancers" description="Your organization's active load balancers."
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
>
|
|
<Toolbar>
|
|
<ToolbarContent>
|
|
<ToolbarSearch />
|
|
<Button>Create</Button>
|
|
</ToolbarContent>
|
|
</Toolbar>
|
|
</DataTable>
|
|
|
|
### With toolbar (small size)
|
|
|
|
<DataTable size="short" title="Load balancers" description="Your organization's active load balancers."
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
>
|
|
<Toolbar size="sm">
|
|
<ToolbarContent>
|
|
<ToolbarSearch />
|
|
<Button>Create</Button>
|
|
</ToolbarContent>
|
|
</Toolbar>
|
|
</DataTable>
|
|
|
|
### Zebra stripes
|
|
|
|
<DataTable zebra
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
/>
|
|
|
|
### Tall rows
|
|
|
|
<DataTable size="tall"
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
/>
|
|
|
|
### Short rows
|
|
|
|
<DataTable size="short"
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
/>
|
|
|
|
### Compact rows
|
|
|
|
<DataTable size="compact"
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
/>
|
|
|
|
### Sortable
|
|
|
|
<DataTable sortable
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
/>
|
|
|
|
|
|
### Selectable
|
|
|
|
<FileSource src="/framed/DataTable/SelectableDataTable" />
|
|
|
|
### Initial selected rows
|
|
|
|
<FileSource src="/framed/DataTable/DataTableBatchSelection" />
|
|
|
|
### Selectable with batch actions
|
|
|
|
<FileSource src="/framed/DataTable/DataTableBatchSelectionToolbar" />
|
|
|
|
### Selectable (radio)
|
|
|
|
<FileSource src="/framed/DataTable/RadioSelectableDataTable" />
|
|
|
|
### Expandable
|
|
|
|
<DataTable expandable
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
>
|
|
<div slot="expanded-row" let:row>
|
|
<pre>
|
|
{JSON.stringify(row, null, 2)}
|
|
</pre>
|
|
</div>
|
|
</DataTable>
|
|
|
|
### Batch expansion
|
|
|
|
<DataTable batchExpansion
|
|
headers="{[
|
|
{ key: "name", value: "Name" },
|
|
{ key: "protocol", value: "Protocol" },
|
|
{ key: "port", value: "Port" },
|
|
{ key: "rule", value: "Rule" }
|
|
]}"
|
|
rows="{[
|
|
{
|
|
id: "a",
|
|
name: "Load Balancer 3",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "b",
|
|
name: "Load Balancer 1",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "c",
|
|
name: "Load Balancer 2",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
{
|
|
id: "d",
|
|
name: "Load Balancer 6",
|
|
protocol: "HTTP",
|
|
port: 3000,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "e",
|
|
name: "Load Balancer 4",
|
|
protocol: "HTTP",
|
|
port: 443,
|
|
rule: "Round robin"
|
|
},
|
|
{
|
|
id: "f",
|
|
name: "Load Balancer 5",
|
|
protocol: "HTTP",
|
|
port: 80,
|
|
rule: "DNS delegation"
|
|
},
|
|
]}"
|
|
>
|
|
<div slot="expanded-row" let:row>
|
|
<pre>
|
|
{JSON.stringify(row, null, 2)}
|
|
</pre>
|
|
</div>
|
|
</DataTable>
|
|
|
|
### Skeleton
|
|
|
|
<DataTableSkeleton />
|
|
|
|
### Skeleton with headers, row count
|
|
|
|
<DataTableSkeleton headers={["Name", "Protocol", "Port", "Rule"]} rows={10} />
|
|
|
|
### Skeleton without header, toolbar
|
|
|
|
<DataTableSkeleton showHeader={false} showToolbar={false} />
|
|
|
|
### Skeleton (tall size)
|
|
|
|
<DataTableSkeleton showHeader={false} showToolbar={false} size="tall" />
|
|
|
|
### Skeleton (short size)
|
|
|
|
<DataTableSkeleton showHeader={false} showToolbar={false} size="short" />
|
|
|
|
### Skeleton (compact size)
|
|
|
|
<DataTableSkeleton showHeader={false} showToolbar={false} size="compact" />
|