# @salmonui/data-grid/engine/export-server API reference

> 14 exported symbols of @salmonui/data-grid/engine/export-server: 5 functions, 5 interfaces and 4 types.

Canonical: https://salmonui.dev/docs/reference/data-grid/engine-export-server

```ts
import { … } from '@salmonui/data-grid/engine/export-server';
```

## Functions

### contentDisposition

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/contentDisposition

```ts
function contentDisposition(fileName: string): string;
```

`Content-Disposition` for a download name (ASCII fallback plus RFC 5987 UTF-8 name).

### createExportDataGrid

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/createExportDataGrid

```ts
function createExportDataGrid<Row>(options: ExportDataGridOptions<Row>): DataGridEngine<Row>;
```

Creates a headless grid (no React, no DOM) with the query modules and the
`export` module (plus `lookup` when a column has one), for server-side
export. `query` is applied first, then a client `state` snapshot.

### createExportStream

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/createExportStream

```ts
function createExportStream<Row>(source: ServerExportSource<Row>, options: ServerExportOptions<Row>, handlers?: ServerExportHandlers<Row>): Promise<ExportStream | null>;
```

Starts an export: raises `onBeforeExport` (null when prevented), builds the
export model, and returns the file name, MIME type, download headers, and
the bytes as an async iterable. Nothing is written until `chunks` is read.

### exportToResponse

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/exportToResponse

```ts
function exportToResponse<Row>(source: ServerExportSource<Row>, options: ServerExportOptions<Row>, handlers?: ServerExportHandlers<Row>, init?: {
    readonly status?: number;
    readonly headers?: Readonly<Record<string, string>>;
}): Promise<PlatformResponse | null>;
```

Exports to a Web `Response` whose body streams the file, with
`Content-Type` and `Content-Disposition` set: return it from a Next.js
route handler or any fetch-style server. Resolves to null when
`onBeforeExport` prevents the export.

### exportToStream

Kind: function

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/exportToStream

```ts
function exportToStream<Row>(source: ServerExportSource<Row>, target: NodeWritableLike | WebWritableStreamLike, options: ServerExportOptions<Row>, handlers?: ServerExportHandlers<Row>): Promise<ExportStreamResult | null>;
```

Streams an export to a Node `Writable` (for example an `http.ServerResponse`
or `fs.createWriteStream`) or a Web `WritableStream`, honoring
backpressure, and ends the target. Resolves to the file name, MIME type,
and byte count, or null when `onBeforeExport` prevents the export (the
target is then left untouched).

## Interfaces

### ExportDataGridOptions

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/ExportDataGridOptions

```ts
interface ExportDataGridOptions<Row> {
    readonly rows: readonly Row[];
    readonly columns: readonly ColumnDef<Row>[];
    readonly getRowId?: (row: Row, index: number) => RowId;
    readonly query?: DataGridQueryInit;
    readonly state?: DataGridState | string;
    readonly locale?: string;
    readonly timeZone?: string;
    readonly currency?: string;
    readonly direction?: 'ltr' | 'rtl';
    readonly tree?: TreeOptions<Row> | true;
}
```

Rows and columns of a headless export grid.

Members (10):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `rows` | `readonly rows: readonly Row[];` |  |  |
| `columns` | `readonly columns: readonly ColumnDef<Row>[];` |  |  |
| `getRowId` | `readonly getRowId?: (row: Row, index: number) => RowId;` | optional | Default: the `primaryKey` column's value, else the row index. |
| `query` | `readonly query?: DataGridQueryInit;` | optional | Sorting, filters, search, grouping, aggregates, and paging. |
| `state` | `readonly state?: DataGridState \| string;` | optional | A client grid state (`getState()`, or its `serializeDataGridState` text), applied after `query`. |
| `locale` | `readonly locale?: string;` | optional |  |
| `timeZone` | `readonly timeZone?: string;` | optional |  |
| `currency` | `readonly currency?: string;` | optional |  |
| `direction` | `readonly direction?: 'ltr' \| 'rtl';` | optional |  |
| `tree` | `readonly tree?: TreeOptions<Row> \| true;` | optional | Tree mode: the same `tree` options as the client grid (`true` means nested rows under `children`). Nested `rows` are flattened here; a client `state` restores `tree.expandedRows`. The export model then carries each row's depth, so XLSX outlines, PDF indentation, and the CSV depth column equal the client export. |

### ExportStream

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/ExportStream

```ts
interface ExportStream {
    readonly fileName: string;
    readonly mimeType: string;
    readonly headers: Readonly<Record<string, string>>;
    readonly chunks: AsyncIterable<Uint8Array>;
}
```

A started export: name, type, download headers, and the bytes as an async iterable.

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `fileName` | `readonly fileName: string;` |  |  |
| `mimeType` | `readonly mimeType: string;` |  |  |
| `headers` | `readonly headers: Readonly<Record<string, string>>;` |  |  |
| `chunks` | `readonly chunks: AsyncIterable<Uint8Array>;` |  |  |

### ExportStreamResult

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/ExportStreamResult

```ts
interface ExportStreamResult {
    readonly fileName: string;
    readonly mimeType: string;
    readonly bytes: number;
}
```

Result of `exportToStream`.

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `fileName` | `readonly fileName: string;` |  |  |
| `mimeType` | `readonly mimeType: string;` |  |  |
| `bytes` | `readonly bytes: number;` |  |  |

### NodeWritableLike

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/NodeWritableLike

```ts
interface NodeWritableLike {
    write(chunk: Uint8Array): boolean;
    end(callback?: () => void): unknown;
    once(event: 'drain' | 'error', listener: (error?: unknown) => void): unknown;
    removeListener(event: 'drain' | 'error', listener: (error?: unknown) => void): unknown;
}
```

The parts of a Node `Writable` the export uses.

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `write` | `write(chunk: Uint8Array): boolean;` |  |  |
| `end` | `end(callback?: () => void): unknown;` |  |  |
| `once` | `once(event: 'drain' \| 'error', listener: (error?: unknown) => void): unknown;` |  |  |
| `removeListener` | `removeListener(event: 'drain' \| 'error', listener: (error?: unknown) => void): unknown;` |  |  |

### WebWritableStreamLike

Kind: interface

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/WebWritableStreamLike

```ts
interface WebWritableStreamLike {
    getWriter(): {
        readonly ready: Promise<unknown>;
        write(chunk: Uint8Array): Promise<void>;
        close(): Promise<void>;
        abort(reason?: unknown): Promise<void>;
    };
}
```

The parts of a Web `WritableStream` the export uses.

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `getWriter` | `getWriter(): {     readonly ready: Promise<unknown>;     write(chunk: Uint8Array): Promise<void>;     close(): Promise<void>;     abort(reason?: unknown): Promise<void>; };` |  |  |

## Types

### PlatformResponse

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/PlatformResponse

```ts
type PlatformResponse = typeof globalThis extends {
    Response: {
        prototype: infer R;
    };
} ? R : unknown;
```

The platform `Response` type where the consumer's environment declares one (DOM lib, `@types/node`).

### ServerExportHandlers

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/ServerExportHandlers

```ts
type ServerExportHandlers<Row> = Omit<ExportHandlers<Row>, 'onExport'>;
```

Hooks and `onBeforeExport`; there is no file promise, so no `onExport`.

Members (6):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `onBeforeExport` | `onBeforeExport?: ((event: BeforeExportEvent) => void);` | optional, inherited | Synchronous; `preventDefault()` cancels. |
| `cell` | `cell?: ((ctx: ExportCellHookContext<Row>) => void \| ExportCellPatch \| null \| undefined);` | optional, inherited | Per data cell. Not called when unset. |
| `headerCell` | `headerCell?: ((ctx: ExportHeaderCellHookContext<Row>) => void \| { readonly text?: string; readonly style?: ExportCellStyle; } \| null \| undefined);` | optional, inherited | Per header cell. |
| `aggregateCell` | `aggregateCell?: ((ctx: ExportAggregateCellHookContext) => void \| { readonly text?: string; readonly style?: ExportCellStyle; } \| null \| undefined);` | optional, inherited | Per aggregate cell (grid footer, group footer, group caption). |
| `groupCaption` | `groupCaption?: ((ctx: ExportGroupCaptionHookContext) => void \| string \| null \| undefined);` | optional, inherited | Group caption text. |
| `detail` | `detail?: ((ctx: ExportDetailContext<Row>) => void \| ExportDetail \| null \| undefined);` | optional, inherited | A detail block written after a data row (text lines or a child table), or null for none. |

### ServerExportOptions

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/ServerExportOptions

```ts
type ServerExportOptions<Row> = ({
    readonly format: 'csv';
} & CsvExportOptions<Row> & Omit<CsvStreamOptions, keyof CsvExportOptions<Row>>) | ({
    readonly format: 'excel';
} & XlsxExportOptions<Row>) | ({
    readonly format: 'pdf';
} & PdfExportOptions<Row>);
```

Options of one server export; `format` selects the writer and its options.

### ServerExportSource

Kind: type

Page: https://salmonui.dev/docs/reference/data-grid/engine-export-server/ServerExportSource

```ts
type ServerExportSource<Row> = ExportSource<Row> | ExportDataGridOptions<Row>;
```

A grid, an export model, or rows and columns.
