Skip to content
Discussion options

You must be logged in to vote

Use the cell slot for every cell and handle both nulls and display inside it. The slot receives cell (with cell.display and cell.value). Check for null first, then call cell.display when it exists.

1. Use display on headers for formatting

const headers = [
  { key: 'name', value: 'Name' },
  { key: 'amount', value: 'Amount', display: (v) => new Intl.NumberFormat().format(v ?? 0) },
];

2. Use the cell slot to hide nulls and apply display

<DataTable {headers} {rows}>
  <svelte:fragment slot="cell" let:cell let:row>
    {#if cell.value == null}
      —
    {:else}
      {cell.display ? cell.display(cell.value, row) : cell.value}
    {/if}
  </svelte:fragment>
</DataTable>

Result: nulls show as

Replies: 2 comments

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
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