AdaptTable for Reka UI

Pivot tables in Reka UI

Grouping answers “what is the total per team”. A pivot answers “what is the total per team per status”, and that second dimension becomes columns your data never had.

Fields move between the three zones with buttons rather than drag, so the pivot can be built from the keyboard. Subtotals close every group and a grand total closes the table.

The configuration — axes, measures, aggregation and what you folded — lives in the URL, so a pivot you build is a pivot you can send someone.

The code

<script setup lang="ts">
import { computed } from "vue";
import {
  pivot, pivotTableModel, usePivotUrlState, type PivotField,
} from "@adapttable/vue/pivot";
import { DataTable } from "@adapttable/reka-ui";
import { pinnedSummaryRows } from "@adapttable/reka-ui/pinned-summary-rows";
import { PivotPanel } from "@adapttable/reka-ui/pivot";

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

const fields: readonly PivotField[] = [
  { key: "team", label: "Team" }, { key: "status", label: "Status" },
  { key: "budget", label: "Budget" },
];
const state = usePivotUrlState({
  urlKey: "p",
  defaultConfig: {
    rows: ["team"], columns: ["status"],
    measures: [{ key: "budget", agg: "sum" }],
  },
});
const model = computed(() => pivotTableModel(
  pivot(props.rows, state.config.value, { collapsed: state.collapsed.value }),
  { fields },
));
</script>

<template>
  <PivotPanel
    :fields="fields" :config="state.config.value"
    :on-change="state.onConfigChange"
  />
  <DataTable
    :data="model.rows" :columns="model.columns" :row-key="model.rowKey"
    :features="[pinnedSummaryRows(model.pinnedRows ?? {})]"
  />
</template>

Install

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

The same feature in the other kits

More Reka UI features

Reference: pivot. More of this kit: AdaptTable for Reka UI, or the live demo.