AdaptTable for Nuxt UI

Spreadsheet formulas in Nuxt UI

A formula column is a column nobody wrote code for: type =ROUND(budget * 0.15, 0) and the table computes it per row, sorts it, filters it and exports it like any other column.

The engine covers arithmetic including POWER and SQRT, comparison, string joins, IF, and the aggregate functions a footer needs. A bad reference reports in the cell that caused it rather than blanking the table, and a circular reference reports #CYCLE! instead of recursing.

Formula columns serialize to the URL with everything else, so a derived column travels in the same link as the filters it sits beside.

The code

<script setup lang="ts">
import { computed } from "vue";
import type { ColumnDef } from "@adapttable/vue";
import { buildFormulaColumns, useFormulaUrlState } from "@adapttable/vue/formula";
import { DataTable } from "@adapttable/nuxt-ui";

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

const rowKey = (row: Person) => row.id;
const state = useFormulaUrlState({
  urlKey: "fx",
  defaultFormulas: [
    { key: "margin", header: "Margin", formula: "=ROUND(budget * 0.15, 0)" },
  ],
});
const columns = computed(() => [
  ...props.baseColumns,
  ...buildFormulaColumns<Person>(state.formulas.value).columns,
]);
</script>

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

Install

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

The same feature in the other kits

More Nuxt UI features

Reference: formulas. More of this kit: AdaptTable for Nuxt UI, or the live demo.