How do I make a clickable link for email? #67
-
do I do some sort of magic here?
Also how do I handle null values, so say something other then null Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hey @rgfx, you can use the Because Svelte does not have a JSX-equivalent, you cannot inline the definition. Instead, you will have to use a custom solution we developed: In your case, you will have a component like: <!-- TableEmailLinkCell -->
<script lang="ts">
export let email: string | undefined = undefined;
</script>
{#if email === undefined}
<span>No email</span>
{:else}
<a href="mailto:{email}">{email}</a>
{/if} You would then use it like: const table = createTable();
const columns = table.createColumns([
table.column({
header: 'Email',
accessor: 'email',
cell: ({ value }) =>
createRender(TableEmailLinkCell, {email: value}),
}),
...
]);
...
const table = createTable();
const columns = table.createColumns([
table.column({
header: 'Email',
accessor: 'email',
cell: ({ value }) =>
createRender(TableEmailLinkCell, {email: value})
.on('click', (ev) => handleClick(ev, value)),
}),
...
]);
... |
Beta Was this translation helpful? Give feedback.
-
@bryanmylee Is it possible to pull arbitrary data from other cells in the row? For example, if I wanted to create an email link where the name is pulled from another column? Something like:
Thanks! |
Beta Was this translation helpful? Give feedback.
Hey @rgfx, you can use the
cell
property to define custom rendering options for the column body.https://svelte-headless-table.bryanmylee.com/docs/api/create-columns#columndef-cell-datacell-state-renderconfig
Because Svelte does not have a JSX-equivalent, you cannot inline the definition. Instead, you will have to use a custom solution we developed:
createRender
.In your case, you will have a component like:
You would then use it like: