How do I add a custom function call in svelte code? Eg. in the DataTableTest.svelte, I want to add the cellFormatter function and make it call automatically and render the div inside the . Following are code :
ABC.svelte
import DataTableTest from "./DataTableTest.svelte";
let columns = [
{
label: "ABC",
property: "abc"
},
{
label: "Items",
property: "items"
},
{
label: "cellFormatter",
formatter: function(rowIndex, rowData) {
return "<div>" + rowData[rowIndex] + "</div>";
}
}
];
let data = [
{
"abc": "dsaaads",
"items": "dsadsads",
}
</script>
<DataTableTest title="Test" {data} {columns} />
DataTableTest.svelte
<script>
export let title;
export let data;
export let columns = [];
</script>
{title}
<table>
{#if columns}
<tr>
{#each columns as c}
<td>{c.label}</td>
{/each}
</tr>
{/if}
{#if data}
<tbody>
{#each data as d, i}
<tr>
{#each columns as c}
{#if c.formatter}
<td on:load=c.formatter(i, d)></td>
{:else}
<td>
{@html d[c.property] ? d[c.property] : ''}
</td>
{/if}
{/each}
</tr>
{/each}
</tbody>
{/if}
</table>
I gave a try with
<td on:load=c.formatter(i, d)></td>
But this does not work? Can someone tell how can I do that here?