Skip to content

Adding component to DataTable? #1756

Answered by metonym
omar2205 asked this question in Q&A
Discussion options

You must be logged in to vote

You can use slotted cells to render custom markup per cell.

Svelte REPL

<script>
  import { DataTable, Toggle } from "carbon-components-svelte";
</script>

<DataTable
  headers={[
    { key: "name", value: "Name" },
    { key: "protocol", value: "Protocol" },
    { key: "port", value: "Port" },
    { key: "rule", value: "Rule" },
  ]}
  rows={Array.from({ length: 6 }).map((_, i) => ({
    id: i,
    name: "Load Balancer " + (i + 1),
    protocol: "HTTP",
    port: i % 3 ? (i % 2 ? 3000 : 80) : 443,
    rule: i % 3 ? "Round robin" : "DNS delegation",
  }))}
>
  <svelte:fragment slot="cell" let:row let:cell>
    {#if cell.key === "rule" && cell.value === "Round robin"}
      <Toggle size="sm" 

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@omar2205
Comment options

Answer selected by omar2205
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants