Build a datatable component, step by step.

Sort data

When clicking on the th element, we want the column to be sorted, one move up, the next down.

We create a dedicated component Th.svelte to keep the logic well separated.

We will need to specify which object key will be sorted by passing the orderBy property to the component.

  • Code
  • Result
  • Data