AdaptTable for Naive UI

Row reordering in Naive UI

Compose rowReorder from @adapttable/naive-ui/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/naive-ui";
import { rowReorder } from "@adapttable/naive-ui/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/naive-ui @adapttable/vue @adapttable/core naive-ui

The same feature in the other kits

More Naive UI features

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