# Vue

> Use Birch UI Grid in Vue 3 and Nuxt with the BirchGrid component, options as attributes, kebab-case events and a template ref to the grid API.

`@birchui/vue` wraps every Birch UI widget as a Vue 3 component. `BirchGrid` accepts grid options as attributes or as one `options` object, emits every grid event with a kebab-case name, and exposes the grid API through a template ref. It supports Vue 3.3 and later.

## Install

```bash
npm install @birchui/core @birchui/vue
```

## A complete example

```vue title="OrdersGrid.vue"
<script setup lang="ts">
import { ref, shallowRef } from 'vue';
import { BirchGrid } from '@birchui/vue';
import type { CellValueChangedEvent, ColumnDef, GridApi } from '@birchui/core';

interface Order {
  id: string;
  customer: string;
  region: 'EMEA' | 'Americas' | 'APAC';
  placedAt: string;
  total: number;
}

const usd = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });

const columns: ColumnDef<Order>[] = [
  { field: 'id', header: 'Order', width: 120, pinned: 'left' },
  { field: 'customer', header: 'Customer', flex: 1, filter: 'text', editable: true },
  { field: 'region', header: 'Region', filter: 'set' },
  { field: 'placedAt', header: 'Placed', type: 'date', filter: 'date' },
  { field: 'total', header: 'Total', type: 'number', format: (value) => usd.format(Number(value)) },
];

const getRowId = (order: Order) => order.id;

const orders = shallowRef<Order[]>([
  { id: 'SO-10421', customer: 'Northwind Traders', region: 'EMEA', placedAt: '2026-11-02', total: 1840.5 },
  { id: 'SO-10422', customer: 'Contoso Ltd', region: 'Americas', placedAt: '2026-11-03', total: 312 },
  { id: 'SO-10423', customer: 'Tailspin Toys', region: 'APAC', placedAt: '2026-11-04', total: 96.4 },
]);

const search = ref('');
const selectedCount = ref(0);
const grid = ref<{ api: GridApi<Order> | null } | null>(null);

function onCellValueChanged({ row, colId, newValue }: CellValueChangedEvent<Order>) {
  console.info(`Order ${row.id}: ${colId} changed to ${String(newValue)}`);
}

function exportCsv() {
  grid.value?.api?.downloadCsv({ fileName: 'orders.csv' });
}
</script>

<template>
  <div class="toolbar">
    <input v-model="search" type="search" placeholder="Search orders" />
    <button type="button" @click="exportCsv">Export CSV</button>
    <span>{{ selectedCount }} selected</span>
  </div>

  <BirchGrid
    ref="grid"
    class="orders-grid"
    :columns="columns"
    :rows="orders"
    :get-row-id="getRowId"
    :quick-filter="search"
    row-selection="multiple"
    :checkbox-selection="true"
    @selection-changed="selectedCount = $event.selected.length"
    @cell-value-changed="onCellValueChanged"
  />
</template>

<style scoped>
.orders-grid {
  height: 480px;
}
</style>
```

The component renders one `div` and creates the grid inside it on mount. Size that `div` with `class` or `style`.

## Passing options

There are two ways to pass grid options, and you can combine them.

**As attributes.** Any attribute other than `class`, `style`, `id` and event listeners is treated as a grid option. Kebab-case names are converted to camelCase, so `:get-row-id` and `:getRowId` both set `getRowId`.

```vue
<BirchGrid :columns="columns" :rows="orders" theme="dark" density="compact" :floating-filters="true" />
```

**As one object.** The `options` prop takes any part of [`GridOptions`](https://docs.birchui.com/api/core.md#gridoptions). This is the easiest way to get full type checking in templates:

```vue
<script setup lang="ts">
import type { GridOptions } from '@birchui/core';

const options: Partial<GridOptions<Order>> = {
  columns,
  getRowId: (order) => order.id,
  rowSelection: 'multiple',
  pagination: { pageSize: 50 },
  sort: [{ colId: 'placedAt', dir: 'desc' }],
};
</script>

<template>
  <BirchGrid :options="options" :rows="orders" />
</template>
```

When both are given, attributes win over keys in `options`.

Remember that boolean options need a bound value. Write `:checkbox-selection="true"`, not a bare `checkbox-selection` attribute, which Vue passes as an empty string.

## Events

Every grid event is emitted with its kebab-case name. The listener receives the payload object:

| Grid event | Vue listener |
| --- | --- |
| `ready` | `@ready` |
| `cellClick`, `cellDoubleClick`, `cellKeyDown` | `@cell-click`, `@cell-double-click`, `@cell-key-down` |
| `cellValueChanged` | `@cell-value-changed` |
| `rowClick`, `selectionChanged` | `@row-click`, `@selection-changed` |
| `sortChanged`, `filterChanged` | `@sort-changed`, `@filter-changed` |
| `columnResized`, `columnMoved`, `columnPinned`, `columnVisible`, `columnStateChanged` | `@column-resized`, `@column-moved`, `@column-pinned`, `@column-visible`, `@column-state-changed` |
| `modelUpdated`, `focusChanged`, `viewportScroll`, `pageChanged` | `@model-updated`, `@focus-changed`, `@viewport-scroll`, `@page-changed` |
| `rowExpanded`, `editStart`, `editStop` | `@row-expanded`, `@edit-start`, `@edit-stop` |

## The grid API

The component exposes `api`, the [`GridApi`](https://docs.birchui.com/api/core.md#gridapi) of the grid it created. Read it through a template ref. It is `null` until the component is mounted:

```ts
const grid = ref<{ api: GridApi<Order> | null } | null>(null);

function showLatestFirst() {
  grid.value?.api?.setSort([{ colId: 'placedAt', dir: 'desc' }]);
  grid.value?.api?.scrollToRow(0, 'start');
}
```

The `ready` event also carries the API: `@ready="({ api }) => api.autosizeColumns()"`.

If you keep the API in a variable of your own, use `shallowRef`. The API object is a class instance, which Vue never wraps in a reactive proxy, and `shallowRef` keeps it that way while still letting templates react when you assign it:

```ts
const gridApi = shallowRef<GridApi<Order> | null>(null);

function onReady({ api }: { api: GridApi<Order> }) {
  gridApi.value = api;
}
```

## Reactivity and updates

The grid is created once in `onMounted`. After that, the component compares each option with the value it last sent, by identity, and calls `api.update()` with only the changed keys. It never recreates the grid.

- **Replace arrays instead of mutating them.** `orders.value.push(order)` keeps the same array, so nothing is sent. Write `orders.value = [...orders.value, order]`, or call `grid.value?.api?.applyTransaction({ add: [order] })`.
- **Use `shallowRef` for row data.** A deep `ref` makes every row object reactive, which costs memory and time with tens of thousands of rows and gives the grid proxies instead of your objects. `shallowRef` keeps rows as plain objects and still triggers updates when you assign a new array.
- **Keep columns and callbacks stable.** Define `columns`, `getRowId` and `modules` once in `<script setup>`. Inline arrow functions in the template create a new function on every render, which sends an update each time.
- **The `options` object is watched one level deep.** Changing `options.value.theme` sends `theme`; mutating a nested object inside it does not.

```ts
const orders = shallowRef<Order[]>([]);

async function loadOrders() {
  const response = await fetch('/api/orders?status=open');
  orders.value = await response.json();
}

function markShipped(order: Order) {
  grid.value?.api?.applyTransaction({ update: [{ ...order, status: 'shipped' }] });
}
```

## Typing

`BirchGrid` is not generic in templates, so attributes are not type-checked against your row type. Two patterns keep your code typed:

- Annotate values in `<script setup>`: `ColumnDef<Order>[]`, `Partial<GridOptions<Order>>` and event payloads such as `CellValueChangedEvent<Order>`.
- Pass options through the typed `options` prop.

## Grid Pro

```vue title="RevenueByRegion.vue"
<script setup lang="ts">
import { BirchGrid } from '@birchui/vue';
import { RowGroupingModule, AggregationModule, StatusBarModule } from '@birchui/grid-pro';
import type { ColumnDef } from '@birchui/core';

interface Sale {
  region: string;
  country: string;
  revenue: number;
}

defineProps<{ sales: Sale[] }>();

const modules = [RowGroupingModule, AggregationModule, StatusBarModule];
const columns: ColumnDef<Sale>[] = [
  { field: 'region', header: 'Region', rowGroup: true },
  { field: 'country', header: 'Country' },
  { field: 'revenue', header: 'Revenue', type: 'number', aggFunc: 'sum' },
];
</script>

<template>
  <BirchGrid
    style="height: 520px"
    :columns="columns"
    :rows="sales"
    :modules="modules"
    :group-default-expanded="1"
    :status-bar="true"
  />
</template>
```

Set the license key once in `main.ts` with `setLicenseKey` from `@birchui/license`. See [Licensing and activation](https://docs.birchui.com/getting-started/licensing.md).

## Registering globally

Import the component where you use it, as above, or register it once:

```ts title="main.ts"
import { createApp } from 'vue';
import { BirchGrid } from '@birchui/vue';
import App from './App.vue';

createApp(App).component('BirchGrid', BirchGrid).mount('#app');
```

## Nuxt

The component creates the grid in `onMounted`, which only runs in the browser. During server rendering it outputs its empty container, so it works in Nuxt pages without extra setup. Give the container a height so the layout does not shift when the grid appears.

To skip server rendering of the grid completely, for example to show a skeleton instead, wrap it in `<ClientOnly>`:

```vue title="pages/orders.vue"
<script setup lang="ts">
import { BirchGrid } from '@birchui/vue';
import { columns, type Order } from '~/utils/orders';

const { data: orders } = await useFetch<Order[]>('/api/orders');
</script>

<template>
  <ClientOnly>
    <BirchGrid class="orders-grid" :columns="columns" :rows="orders ?? []" />
    <template #fallback>
      <div class="orders-grid orders-grid-skeleton" aria-busy="true">Loading orders…</div>
    </template>
  </ClientOnly>
</template>
```

Set the license key in a client plugin:

```ts title="plugins/birchui.client.ts"
import { setLicenseKey } from '@birchui/license';

export default defineNuxtPlugin(() => {
  setLicenseKey(useRuntimeConfig().public.birchLicenseKey as string);
});
```

## Wrapping your own widgets

`createVueComponent(definition)` turns any widget that follows the Birch UI widget contract into a Vue component with the same attribute, `options`, event and `api` behaviour. `BirchGrid` and `BirchScheduler` are built with it.

```ts
import { createVueComponent } from '@birchui/vue';
import { shipmentMapDefinition } from './shipment-map';

export const ShipmentMap = createVueComponent(shipmentMapDefinition);
```

## Event Calendar

`@birchui/vue` has no calendar entry point. The Event Calendar follows the same widget contract, so the adapter's generic factory wraps it in one line. See the [Event Calendar overview](https://docs.birchui.com/calendar/overview.md) for its options and events.

```ts title="event-calendar.ts"
import { createVueComponent } from '@birchui/vue';
import { calendarDefinition } from '@birchui/calendar';

export const EventCalendar = createVueComponent(calendarDefinition);
```

```vue title="ClinicCalendar.vue"
<script setup lang="ts">
import { shallowRef } from 'vue';
import type { CalendarEvent } from '@birchui/calendar';
import { EventCalendar } from './event-calendar';

const appointments = shallowRef<CalendarEvent[]>([
  { id: 'appt-1042', title: 'Annual physical: Maria Lopez', start: '2026-12-01T09:15', end: '2026-12-01T09:45' },
]);
</script>

<template>
  <EventCalendar
    style="height: 720px"
    view="week"
    time-zone="Europe/London"
    :slot-minutes="15"
    :events="appointments"
    @event-click="({ event }) => console.info('Open appointment', event.id)"
  />
</template>
```

### Other Birch UI products

Gantt, Pivot Studio, Charts, the diagram editor, the spreadsheet, the form renderer and the Form Builder work the same way: pass `ganttDefinition` from `@birchui/gantt`, `pivotStudioDefinition` from `@birchui/pivot-studio`, `chartDefinition` from `@birchui/charts`, `diagramDefinition` from `@birchui/diagram`, `spreadsheetDefinition` from `@birchui/spreadsheet`, `formDefinition` from `@birchui/forms` or `formBuilderDefinition` from `@birchui/forms/builder` to `createVueComponent`. The [Gantt](https://docs.birchui.com/gantt/overview.md), [Pivot Studio](https://docs.birchui.com/pivot-studio/overview.md), [Charts](https://docs.birchui.com/charts/overview.md), [Diagram](https://docs.birchui.com/diagram/overview.md), [Spreadsheet](https://docs.birchui.com/spreadsheet/overview.md) and [Forms](https://docs.birchui.com/forms/overview.md) overviews have complete examples.

## Next steps

- [Using the Scheduler in your framework](https://docs.birchui.com/frameworks/scheduler.md) for `BirchScheduler`.
- [Updating data](https://docs.birchui.com/grid/updating-data.md) for transactions and row ids.
- The [@birchui/vue API reference](https://docs.birchui.com/api/vue.md).
