AdaptTable for Quasar

Pivot tables in Quasar

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/quasar";
import { pinnedSummaryRows } from "@adapttable/quasar/pinned-summary-rows";
import { PivotPanel } from "@adapttable/quasar/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/quasar @adapttable/vue @adapttable/core quasar@2.34.0

The same feature in the other kits

More Quasar features

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