mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-17 03:01:25 +00:00
feat(data-table): support generics (#1954)
Co-authored-by: K.Kiyokawa <koichi20110068@gmail.com> Co-authored-by: brunnerh <brunnerh@users.noreply.github.com>
This commit is contained in:
parent
752c46b94c
commit
dd43224119
13 changed files with 278 additions and 132 deletions
|
@ -10,16 +10,15 @@
|
|||
Button,
|
||||
Link,
|
||||
} from "carbon-components-svelte";
|
||||
import type { DataTableHeader } from "carbon-components-svelte/DataTable/DataTable.svelte";
|
||||
import Launch from "carbon-icons-svelte/lib/Launch.svelte";
|
||||
import type { ComponentProps } from "svelte";
|
||||
|
||||
const headers: DataTableHeader[] = [
|
||||
const headers = [
|
||||
{ key: "name", value: "Name" },
|
||||
{ key: "protocol", value: "Protocol", width: "400px", minWidth: "40%" },
|
||||
{ key: "port", value: "Port" },
|
||||
{ key: "rule", value: "Rule", sort: false },
|
||||
];
|
||||
] as const;
|
||||
const rows = [
|
||||
{
|
||||
id: "a",
|
||||
|
@ -285,3 +284,67 @@
|
|||
<DataTableSkeleton showHeader="{false}" showToolbar="{false}" size="short" />
|
||||
|
||||
<DataTableSkeleton showHeader="{false}" showToolbar="{false}" size="compact" />
|
||||
|
||||
<DataTable
|
||||
rows="{[
|
||||
{
|
||||
name: 'Load Balancer 3',
|
||||
protocol: 'HTTP',
|
||||
port: 3000,
|
||||
rule: 'Round robin',
|
||||
id: '-',
|
||||
},
|
||||
]}"
|
||||
headers="{[
|
||||
{
|
||||
key: 'name',
|
||||
value: 'Name',
|
||||
},
|
||||
{
|
||||
key: 'protocol',
|
||||
value: 'Protocol',
|
||||
display: (value) => {
|
||||
return value + ' Protocol';
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'port',
|
||||
value: 'Port',
|
||||
display: (value, row) => {
|
||||
console.log(row.port);
|
||||
return value + ' €';
|
||||
},
|
||||
sort: (a, b) => {
|
||||
if (a > b) return 1;
|
||||
return 0;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'rule',
|
||||
value: 'Rule',
|
||||
},
|
||||
]}"
|
||||
sortKey="name"
|
||||
on:click:row="{(e) => {
|
||||
const detail = e.detail;
|
||||
detail.name;
|
||||
detail.port;
|
||||
}}"
|
||||
on:click:cell="{(e) => {
|
||||
const detail = e.detail;
|
||||
switch (detail.key) {
|
||||
case 'name':
|
||||
detail.value;
|
||||
break;
|
||||
}
|
||||
}}"
|
||||
on:click="{(e) => {
|
||||
e.detail.cell;
|
||||
e.detail.row?.name;
|
||||
}}"
|
||||
on:click:row--expand="{(e) => {
|
||||
const detail = e.detail;
|
||||
detail.row.id;
|
||||
detail.row.name;
|
||||
}}"
|
||||
/>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
{ key: "port", value: "Port" },
|
||||
{ key: "rule", value: "Rule" },
|
||||
{ key: "overflow", empty: true },
|
||||
];
|
||||
] as const;
|
||||
|
||||
const rows = [
|
||||
{ id: "a", name: "Load Balancer 3", port: 3000, rule: "Round robin" },
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{ key: "name", value: "Name" },
|
||||
{ key: "port", value: "Port" },
|
||||
{ key: "rule", value: "Rule" },
|
||||
];
|
||||
] as const;
|
||||
|
||||
const rows = [
|
||||
{ id: "a", name: "Load Balancer 3", port: 3000, rule: "Round robin" },
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
{ key: "name", value: "Name" },
|
||||
{ key: "port", value: "Port" },
|
||||
{ key: "rule", value: "Rule" },
|
||||
];
|
||||
] as const;
|
||||
|
||||
const rows = [
|
||||
{ id: "a", name: "Load Balancer 3", port: 3000, rule: "Round robin" },
|
||||
|
|
30
tests/DataTableNestedHeaders.test.svelte
Normal file
30
tests/DataTableNestedHeaders.test.svelte
Normal file
|
@ -0,0 +1,30 @@
|
|||
<script lang="ts">
|
||||
import { DataTable } from "../types";
|
||||
</script>
|
||||
|
||||
<DataTable
|
||||
headers="{[
|
||||
{ key: 'name', value: 'Name' },
|
||||
{ key: 'protocol', value: 'Protocol', width: '400px', minWidth: '40%' },
|
||||
{ key: 'port', value: 'Port' },
|
||||
{ key: 'rule.name', value: 'Rule', sort: false },
|
||||
]}"
|
||||
rows="{[
|
||||
{
|
||||
id: 'a',
|
||||
name: 'Load Balancer 3',
|
||||
protocol: 'HTTP',
|
||||
port: 3000,
|
||||
'rule.name': 'Round robin',
|
||||
},
|
||||
]}"
|
||||
>
|
||||
<span slot="cell" let:cell let:row>
|
||||
{cell.key === "rule.name"}
|
||||
{#if cell.key === "name"}
|
||||
{row.name} {row.id}
|
||||
{:else}
|
||||
{cell.value}
|
||||
{/if}
|
||||
</span>
|
||||
</DataTable>
|
|
@ -5,7 +5,7 @@
|
|||
{ key: "name", value: "Name" },
|
||||
{ key: "port", value: "Port" },
|
||||
{ key: "rule", value: "Rule" },
|
||||
];
|
||||
] as const;
|
||||
|
||||
const rows = [
|
||||
{ id: "a", name: "Load Balancer 3", port: 3000, rule: "Round robin" },
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{ key: "name", value: "Name" },
|
||||
{ key: "port", value: "Port" },
|
||||
{ key: "rule", value: "Rule" },
|
||||
];
|
||||
] as const;
|
||||
|
||||
const rows = [
|
||||
{ id: "a", name: "Load Balancer 3", port: 3000, rule: "Round robin" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue