Cell components

For any cell whose content is more than a string, use cell: with renderSnippet or renderComponent.

Snippet

<script lang="ts">
  import { renderSnippet, type ColumnDef } from 'sv-grid-community'

  const columns: ColumnDef<{}, Person>[] = [
    {
      field: 'status',
      header: 'Status',
      cell: (ctx) => renderSnippet(Pill, { value: String(ctx.getValue()) }),
    },
  ]
</script>

{#snippet Pill(p: { value: string })}
  <span class="pill pill-{p.value}">{p.value}</span>
{/snippet}

Snippets are the right choice when the renderer is local to the page and small.

Component

import StatusBadge from './StatusBadge.svelte'
import { renderComponent } from 'sv-grid-community'

{
  field: 'status',
  cell: (ctx) => renderComponent(StatusBadge, { status: ctx.getValue() }),
}

Components are the right choice when the renderer is reused across multiple grids, has its own state, or needs lifecycle hooks.

CellContext

The argument the grid passes to your cell callback:

type CellContext<TData> = {
  cell: Cell<TData>
  row: Row<TData>
  column: Column<TData>
  table: SvGrid<TData>
  getValue: () => unknown
}

Inline string

If your cell content is a plain string and you just want to format it, use format or formatter - not cell. See Text formatting.

Performance

Cell renderers run once per visible cell on each grid update. For large virtualized grids, keep them cheap:

Common patterns

See also