DataTable header Display vs svelte:fragment #1155
-
|
Is it posible to combine header Display and fragment on same datatable? I managed to use both but not together. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hello, can you please provide details such as a code snippet or screenshot of what you want to modify? |
Beta Was this translation helpful? Give feedback.
-
|
Use the 1. Use const headers = [
{ key: 'name', value: 'Name' },
{ key: 'amount', value: 'Amount', display: (v) => new Intl.NumberFormat().format(v ?? 0) },
];2. Use the <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 3. Different behavior per column <svelte:fragment slot="cell" let:cell let:row>
{#if cell.value == null}
—
{:else if cell.key === 'amount'}
{cell.display ? cell.display(cell.value, row) : cell.value}
{:else}
{cell.value}
{/if}
</svelte:fragment> |
Beta Was this translation helpful? Give feedback.
Use the
cellslot for every cell and handle both nulls anddisplayinside it. The slot receivescell(withcell.displayandcell.value). Check for null first, then callcell.displaywhen it exists.1. Use
displayon headers for formattingconst headers = [ { key: 'name', value: 'Name' }, { key: 'amount', value: 'Amount', display: (v) => new Intl.NumberFormat().format(v ?? 0) }, ];2. Use the
cellslot to hide nulls and applydisplayResult: nulls show as