Skip to content

No way to customize TableRow #1478

Answered by metonym
mkf-simpson asked this question in Q&A
Discussion options

You must be logged in to vote

You could compute the row IDs that contain a certain value and use those IDs to style the corresponding rows.

In the following example:

  1. Get row IDs with rows with a port value of 80
  2. Create a CSS selector that matches [data-row="<id>"]
  3. Inject the styles in svelte:head, which are applied globally

Svelte REPL

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

  const 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",
  }));

  const rowsWithPort80 = rows
    .filter((row) => row.port === 80)
    .map((row) => row.

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by metonym
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
2 participants
Converted from issue

This discussion was converted from issue #1466 on September 03, 2022 14:57.