그리드 전체의 내보내기 기본값Grid-wide export defaults
exportDefaults에 CSV·xlsx·PDF별 기본 옵션을 적어 두면 호출마다 반복하지 않아도 돼요. 호출에서 준 옵션이 기본값을 덮어요(옵션 키마다).Put default options per format (CSV, xlsx, PDF) in exportDefaults and you do not repeat them on every call. An option passed on the call overrides the default, key by key.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<button type="button" id="csvDefault">CSV (기본값)</button>
<button type="button" id="csvComma">CSV (쉼표로 덮어쓰기)</button>
<button type="button" id="xlsx">xlsx 내려받기</button>
</div>
<div id="grid" style="height: 200px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('csvDefault').addEventListener('click', () => actions.csvDefault(api));
document.getElementById('csvComma').addEventListener('click', () => actions.csvComma(api));
document.getElementById('xlsx').addEventListener('click', () => actions.xlsx(api));import { withExport } from '@maxgrid/export';
// exportDefaults는 형식별 기본 옵션이에요. 호출 옵션이 있으면 그 키만 기본값을 덮어요.
export const options = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: '노트북', qty: 3 },
{ id: 2, item: '모니터', qty: 10 },
{ id: 3, item: '키보드', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: '주문', freezeHeader: true },
},
};
let say = () => undefined;
export function setup(api, log) {
say = log;
withExport(api);
}
export const actions = {
csvDefault: (api) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api) => say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api) => {
await withExport(api).downloadXlsx('주문.xlsx');
say({ ko: '시트 이름 "주문"으로 내려받았어요.', en: 'Downloaded with the sheet name "주문".' });
},
}; 이 HTML은 추가 번들(위 script 태그)도 함께 불러오고 전역 변수로 써요. 별도 설치는 필요 없어요.
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>그리드 전체의 내보내기 기본값</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="csvDefault">CSV (기본값)</button>
<button type="button" id="csvComma">CSV (쉼표로 덮어쓰기)</button>
<button type="button" id="xlsx">xlsx 내려받기</button>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.export.min.js"></script>
<script>
const { withExport } = MaxGridExport;
// exportDefaults는 형식별 기본 옵션이에요. 호출 옵션이 있으면 그 키만 기본값을 덮어요.
const options = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: '노트북', qty: 3 },
{ id: 2, item: '모니터', qty: 10 },
{ id: 3, item: '키보드', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: '주문', freezeHeader: true },
},
};
let say = () => undefined;
function setup(api, log) {
say = log;
withExport(api);
}
const actions = {
csvDefault: (api) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api) => say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api) => {
await withExport(api).downloadXlsx('주문.xlsx');
say({ ko: '시트 이름 "주문"으로 내려받았어요.', en: 'Downloaded with the sheet name "주문".' });
},
};
options.ariaLabel = "그리드 전체의 내보내기 기본값";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('csvDefault').addEventListener('click', () => actions.csvDefault(api));
document.getElementById('csvComma').addEventListener('click', () => actions.csvComma(api));
document.getElementById('xlsx').addEventListener('click', () => actions.xlsx(api));
</script>
</body>
</html> 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/react @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.csvDefault(api)}
>CSV (기본값)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.csvComma(api)}
>CSV (쉼표로 덮어쓰기)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.xlsx(api)}
>xlsx 내려받기</button>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
item: string;
qty: number;
}
// exportDefaults는 형식별 기본 옵션이에요. 호출 옵션이 있으면 그 키만 기본값을 덮어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: '노트북', qty: 3 },
{ id: 2, item: '모니터', qty: 10 },
{ id: 3, item: '키보드', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: '주문', freezeHeader: true },
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
csvDefault: (api: GridApi<Row>) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api: GridApi<Row>) =>
say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('주문.xlsx');
say({ ko: '시트 이름 "주문"으로 내려받았어요.', en: 'Downloaded with the sheet name "주문".' });
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/vue @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button
type="button"
:disabled="!api"
@click="api && actions.csvDefault(api)"
>CSV (기본값)</button>
<button
type="button"
:disabled="!api"
@click="api && actions.csvComma(api)"
>CSV (쉼표로 덮어쓰기)</button>
<button type="button" :disabled="!api" @click="api && actions.xlsx(api)">xlsx 내려받기</button>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
item: string;
qty: number;
}
// exportDefaults는 형식별 기본 옵션이에요. 호출 옵션이 있으면 그 키만 기본값을 덮어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: '노트북', qty: 3 },
{ id: 2, item: '모니터', qty: 10 },
{ id: 3, item: '키보드', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: '주문', freezeHeader: true },
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
csvDefault: (api: GridApi<Row>) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api: GridApi<Row>) =>
say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('주문.xlsx');
say({ ko: '시트 이름 "주문"으로 내려받았어요.', en: 'Downloaded with the sheet name "주문".' });
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/angular @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.csvDefault(api)"
>CSV (기본값)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.csvComma(api)"
>CSV (쉼표로 덮어쓰기)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.xlsx(api)"
>xlsx 내려받기</button>
</div>
<mx-grid style="height: 200px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
item: string;
qty: number;
}
// exportDefaults는 형식별 기본 옵션이에요. 호출 옵션이 있으면 그 키만 기본값을 덮어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'qty', title: '수량', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: '노트북', qty: 3 },
{ id: 2, item: '모니터', qty: 10 },
{ id: 3, item: '키보드', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: '주문', freezeHeader: true },
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
csvDefault: (api: GridApi<Row>) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api: GridApi<Row>) =>
say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('주문.xlsx');
say({ ko: '시트 이름 "주문"으로 내려받았어요.', en: 'Downloaded with the sheet name "주문".' });
},
}; This example needs an extra package. To run it locally, install with npm i maxgrid @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="csvDefault">CSV (defaults)</button>
<button type="button" id="csvComma">CSV (override with comma)</button>
<button type="button" id="xlsx">Download xlsx</button>
</div>
<div id="grid" style="height: 200px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('csvDefault').addEventListener('click', () => actions.csvDefault(api));
document.getElementById('csvComma').addEventListener('click', () => actions.csvComma(api));
document.getElementById('xlsx').addEventListener('click', () => actions.xlsx(api));import { withExport } from '@maxgrid/export';
// exportDefaults holds default options per format. Keys given in the call override only those defaults.
export const options = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: 'Laptop', qty: 3 },
{ id: 2, item: 'Monitor', qty: 10 },
{ id: 3, item: 'Keyboard', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: 'Orders', freezeHeader: true },
},
};
let say = () => undefined;
export function setup(api, log) {
say = log;
withExport(api);
}
export const actions = {
csvDefault: (api) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api) => say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api) => {
await withExport(api).downloadXlsx('orders.xlsx');
say('Downloaded with the sheet name "Orders".');
},
};This HTML also loads an extra bundle (the extra script tag above) and uses it as a global. No install is needed.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Grid-wide export defaults</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="csvDefault">CSV (defaults)</button>
<button type="button" id="csvComma">CSV (override with comma)</button>
<button type="button" id="xlsx">Download xlsx</button>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.export.min.js"></script>
<script>
const { withExport } = MaxGridExport;
// exportDefaults holds default options per format. Keys given in the call override only those defaults.
const options = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: 'Laptop', qty: 3 },
{ id: 2, item: 'Monitor', qty: 10 },
{ id: 3, item: 'Keyboard', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: 'Orders', freezeHeader: true },
},
};
let say = () => undefined;
function setup(api, log) {
say = log;
withExport(api);
}
const actions = {
csvDefault: (api) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api) => say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api) => {
await withExport(api).downloadXlsx('orders.xlsx');
say('Downloaded with the sheet name "Orders".');
},
};
options.ariaLabel = "Grid-wide export defaults";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('csvDefault').addEventListener('click', () => actions.csvDefault(api));
document.getElementById('csvComma').addEventListener('click', () => actions.csvComma(api));
document.getElementById('xlsx').addEventListener('click', () => actions.xlsx(api));
</script>
</body>
</html> This example needs an extra package. To run it locally, install with npm i @maxgrid/react @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.csvDefault(api)}
>CSV (defaults)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.csvComma(api)}
>CSV (override with comma)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.xlsx(api)}
>Download xlsx</button>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
item: string;
qty: number;
}
// exportDefaults holds default options per format. Keys given in the call override only those defaults.
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: 'Laptop', qty: 3 },
{ id: 2, item: 'Monitor', qty: 10 },
{ id: 3, item: 'Keyboard', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: 'Orders', freezeHeader: true },
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
csvDefault: (api: GridApi<Row>) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api: GridApi<Row>) =>
say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('orders.xlsx');
say('Downloaded with the sheet name "Orders".');
},
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/vue @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<button
type="button"
:disabled="!api"
@click="api && actions.csvDefault(api)"
>CSV (defaults)</button>
<button
type="button"
:disabled="!api"
@click="api && actions.csvComma(api)"
>CSV (override with comma)</button>
<button type="button" :disabled="!api" @click="api && actions.xlsx(api)">Download xlsx</button>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
item: string;
qty: number;
}
// exportDefaults holds default options per format. Keys given in the call override only those defaults.
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: 'Laptop', qty: 3 },
{ id: 2, item: 'Monitor', qty: 10 },
{ id: 3, item: 'Keyboard', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: 'Orders', freezeHeader: true },
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
csvDefault: (api: GridApi<Row>) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api: GridApi<Row>) =>
say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('orders.xlsx');
say('Downloaded with the sheet name "Orders".');
},
}; This example needs an extra package. To run it locally, install with npm i @maxgrid/angular @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.csvDefault(api)"
>CSV (defaults)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.csvComma(api)"
>CSV (override with comma)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.xlsx(api)"
>Download xlsx</button>
</div>
<mx-grid style="height: 200px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
item: string;
qty: number;
}
// exportDefaults holds default options per format. Keys given in the call override only those defaults.
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 90 },
],
rows: [
{ id: 1, item: 'Laptop', qty: 3 },
{ id: 2, item: 'Monitor', qty: 10 },
{ id: 3, item: 'Keyboard', qty: 25 },
],
rowKey: 'id',
exportDefaults: {
csv: { delimiter: ';', bom: false, newline: '\n' },
xlsx: { sheetName: 'Orders', freezeHeader: true },
},
};
let say: (message: LogText) => void = () => undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api);
}
export const actions = {
csvDefault: (api: GridApi<Row>) => say(withExport(api).exportCsv().split('\n').join(' | ')),
csvComma: (api: GridApi<Row>) =>
say(withExport(api).exportCsv({ delimiter: ',' }).split('\n').join(' | ')),
xlsx: async (api: GridApi<Row>) => {
await withExport(api).downloadXlsx('orders.xlsx');
say('Downloaded with the sheet name "Orders".');
},
};