AdaptTable for shadcn-vue

Row reordering in shadcn-vue

Compose rowReorder from @adapttable/shadcn-vue/row-reorder and a grip appears on every row. Drag it, or press Space to lift a row, the arrows to move it and Space to drop it; a live region announces each step.

The table never mutates your array: onRowReorder asks the host with the row's old and new positions and the row itself, and the host writes. This page applies each move with core's applyRowReorder and says what it did.

The code

<script setup lang="ts">
import { applyRowReorder } from "@adapttable/core";
import { shallowRef } from "vue";
import type { ColumnDef } from "@adapttable/vue";
import { DataTable } from "@adapttable/shadcn-vue";
import { rowReorder } from "@adapttable/shadcn-vue/row-reorder";

const props = defineProps<{ rows: readonly Person[] }>();

const columns: ColumnDef<Person>[] = [
  { key: "name", sortable: true },
  { key: "team" },
  { key: "budget", sortable: true },
];
const rowKey = (row: Person) => row.id;
const order = shallowRef<readonly Person[] | null>(null);
const features = [
  rowReorder<Person>((from, to) => {
    order.value = applyRowReorder(order.value ?? props.rows, from, to);
  }),
];
</script>

<template>
  <DataTable
    :data="order ?? rows"
    :columns="columns"
    :row-key="rowKey"
    :features="features"
  />
</template>

Install

pnpm add @adapttable/shadcn-vue @adapttable/vue @adapttable/core reka-ui

The same feature in the other kits

More shadcn-vue features

Reference: row-reordering. More of this kit: AdaptTable for shadcn-vue, or the live demo.