보이는 행을 XML로 내보내기Export the visible rows as XML
exportXml()은 UTF-8 선언 아래 뿌리 요소와 행 요소를 만들고 컬럼 하나를 요소 하나로 써요. 요소 이름은 컬럼 id이고 쓸 수 없는 이름이면 <cell id="…">예요. 배열은 <item>, 없는 값은 nil="true"이며 글자는 모두 이스케이프하고 쓸 수 없는 제어 문자는 빼요. root·rowTag·pretty로 모양을 바꿔요.exportXml() writes a root element and row elements under a UTF-8 declaration, one element per column. The element name is the column id, or <cell id="…"> when it cannot be a name. Arrays become <item>, missing values nil="true", all text is escaped and invalid control characters are dropped. root, rowTag and pretty change the shape.
코드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="xml">XML 보기</button>
<button type="button" id="custom">요소 이름 바꾸기</button>
<button type="button" id="roundtrip">다시 읽기</button>
</div>
<div id="grid" style="height: 300px"></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('xml').addEventListener('click', () => actions.xml(api));
document.getElementById('custom').addEventListener('click', () => actions.custom(api));
document.getElementById('roundtrip').addEventListener('click', () => actions.roundtrip(api));import { withExport } from '@maxgrid/export';
const rows = [
{ id: 1, name: '김하늘', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: '이도윤 <팀장>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{ id: 3, name: '박서연 & 최지우', dept: 'dev', joined: '2025-01-15', active: true, tags: ['b'] },
];
export const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'name', title: '이름', width: 150 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 110,
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'joined', title: '입사일', kind: 'date', width: 110 },
{ id: 'active', title: '재직', kind: 'boolean', width: 70 },
{
id: 'tags',
title: '태그',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: '알파' },
{ value: 'b', label: '베타' },
],
},
],
rows,
rowKey: 'id',
};
let say = () => { };
let ex;
export function setup(api, log) {
say = log;
ex = withExport(api);
log({
ko: 'api.exportXml()은 UTF-8 선언 아래 <rows><row>…</row></rows>를 만들어요. 글자는 모두 이스케이프돼요.',
en: 'api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.',
});
}
/** 기록은 위가 최신이라 거꾸로 적어야 위에서 아래로 읽혀요. */
function show(text) {
for (const line of text.split('\n').reverse())
say(line);
}
export const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say({
ko: '이름의 < & 는 < &로, 빈 태그는 <tags/>로 나와요.',
en: 'The < and & in a name become < and &, and empty tags give <tags/>.',
});
},
custom: () => {
show(ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'');
say({
ko: 'root·rowTag로 요소 이름을 바꾸고 pretty: false로 한 줄이에요.',
en: 'root and rowTag rename the elements and pretty: false gives one line.',
});
},
roundtrip: (api) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say({
ko: `다시 읽으면 ${back?.rows.length}행, 건너뜀 ${back?.skipped}, 알림 ${back?.errors.length}건이에요. 내보낸 XML은 그대로 읽혀요.`,
en: `Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`,
});
api.getRowCount();
},
}; 이 HTML은 추가 번들(위 script 태그)도 함께 불러오고 전역 변수로 써요. 별도 설치는 필요 없어요.
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>보이는 행을 XML로 내보내기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="xml">XML 보기</button>
<button type="button" id="custom">요소 이름 바꾸기</button>
<button type="button" id="roundtrip">다시 읽기</button>
</div>
<div id="grid" style="height: 300px"></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;
const rows = [
{ id: 1, name: '김하늘', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: '이도윤 <팀장>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{ id: 3, name: '박서연 & 최지우', dept: 'dev', joined: '2025-01-15', active: true, tags: ['b'] },
];
const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'name', title: '이름', width: 150 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 110,
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'joined', title: '입사일', kind: 'date', width: 110 },
{ id: 'active', title: '재직', kind: 'boolean', width: 70 },
{
id: 'tags',
title: '태그',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: '알파' },
{ value: 'b', label: '베타' },
],
},
],
rows,
rowKey: 'id',
};
let say = () => { };
let ex;
function setup(api, log) {
say = log;
ex = withExport(api);
log({
ko: 'api.exportXml()은 UTF-8 선언 아래 <rows><row>…</row></rows>를 만들어요. 글자는 모두 이스케이프돼요.',
en: 'api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.',
});
}
/** 기록은 위가 최신이라 거꾸로 적어야 위에서 아래로 읽혀요. */
function show(text) {
for (const line of text.split('\n').reverse())
say(line);
}
const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say({
ko: '이름의 < & 는 < &로, 빈 태그는 <tags/>로 나와요.',
en: 'The < and & in a name become < and &, and empty tags give <tags/>.',
});
},
custom: () => {
show(ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'');
say({
ko: 'root·rowTag로 요소 이름을 바꾸고 pretty: false로 한 줄이에요.',
en: 'root and rowTag rename the elements and pretty: false gives one line.',
});
},
roundtrip: (api) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say({
ko: `다시 읽으면 ${back?.rows.length}행, 건너뜀 ${back?.skipped}, 알림 ${back?.errors.length}건이에요. 내보낸 XML은 그대로 읽혀요.`,
en: `Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`,
});
api.getRowCount();
},
};
options.ariaLabel = "보이는 행을 XML로 내보내기";
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('xml').addEventListener('click', () => actions.xml(api));
document.getElementById('custom').addEventListener('click', () => actions.custom(api));
document.getElementById('roundtrip').addEventListener('click', () => actions.roundtrip(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.xml(api)}
>XML 보기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.custom(api)}
>요소 이름 바꾸기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.roundtrip(api)}
>다시 읽기</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import { withExport, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
joined: string;
active: boolean;
tags: string[];
}
const rows: Row[] = [
{ id: 1, name: '김하늘', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: '이도윤 <팀장>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{ id: 3, name: '박서연 & 최지우', dept: 'dev', joined: '2025-01-15', active: true, tags: ['b'] },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'name', title: '이름', width: 150 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 110,
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'joined', title: '입사일', kind: 'date', width: 110 },
{ id: 'active', title: '재직', kind: 'boolean', width: 70 },
{
id: 'tags',
title: '태그',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: '알파' },
{ value: 'b', label: '베타' },
],
},
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log({
ko: 'api.exportXml()은 UTF-8 선언 아래 <rows><row>…</row></rows>를 만들어요. 글자는 모두 이스케이프돼요.',
en: 'api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.',
});
}
/** 기록은 위가 최신이라 거꾸로 적어야 위에서 아래로 읽혀요. */
function show(text: string): void {
for (const line of text.split('\n').reverse()) say(line);
}
export const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say({
ko: '이름의 < & 는 < &로, 빈 태그는 <tags/>로 나와요.',
en: 'The < and & in a name become < and &, and empty tags give <tags/>.',
});
},
custom: () => {
show(
ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'',
);
say({
ko: 'root·rowTag로 요소 이름을 바꾸고 pretty: false로 한 줄이에요.',
en: 'root and rowTag rename the elements and pretty: false gives one line.',
});
},
roundtrip: (api: GridApi<Row>) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say({
ko: `다시 읽으면 ${back?.rows.length}행, 건너뜀 ${back?.skipped}, 알림 ${back?.errors.length}건이에요. 내보낸 XML은 그대로 읽혀요.`,
en: `Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`,
});
api.getRowCount();
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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.xml(api)">XML 보기</button>
<button type="button" :disabled="!api" @click="api && actions.custom(api)">요소 이름 바꾸기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.roundtrip(api)"
>다시 읽기</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import { withExport, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
joined: string;
active: boolean;
tags: string[];
}
const rows: Row[] = [
{ id: 1, name: '김하늘', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: '이도윤 <팀장>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{ id: 3, name: '박서연 & 최지우', dept: 'dev', joined: '2025-01-15', active: true, tags: ['b'] },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'name', title: '이름', width: 150 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 110,
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'joined', title: '입사일', kind: 'date', width: 110 },
{ id: 'active', title: '재직', kind: 'boolean', width: 70 },
{
id: 'tags',
title: '태그',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: '알파' },
{ value: 'b', label: '베타' },
],
},
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log({
ko: 'api.exportXml()은 UTF-8 선언 아래 <rows><row>…</row></rows>를 만들어요. 글자는 모두 이스케이프돼요.',
en: 'api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.',
});
}
/** 기록은 위가 최신이라 거꾸로 적어야 위에서 아래로 읽혀요. */
function show(text: string): void {
for (const line of text.split('\n').reverse()) say(line);
}
export const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say({
ko: '이름의 < & 는 < &로, 빈 태그는 <tags/>로 나와요.',
en: 'The < and & in a name become < and &, and empty tags give <tags/>.',
});
},
custom: () => {
show(
ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'',
);
say({
ko: 'root·rowTag로 요소 이름을 바꾸고 pretty: false로 한 줄이에요.',
en: 'root and rowTag rename the elements and pretty: false gives one line.',
});
},
roundtrip: (api: GridApi<Row>) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say({
ko: `다시 읽으면 ${back?.rows.length}행, 건너뜀 ${back?.skipped}, 알림 ${back?.errors.length}건이에요. 내보낸 XML은 그대로 읽혀요.`,
en: `Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`,
});
api.getRowCount();
},
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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.xml(api)"
>XML 보기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.custom(api)"
>요소 이름 바꾸기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.roundtrip(api)"
>다시 읽기</button>
</div>
<mx-grid style="height: 300px" [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, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
dept: string;
joined: string;
active: boolean;
tags: string[];
}
const rows: Row[] = [
{ id: 1, name: '김하늘', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: '이도윤 <팀장>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{ id: 3, name: '박서연 & 최지우', dept: 'dev', joined: '2025-01-15', active: true, tags: ['b'] },
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'name', title: '이름', width: 150 },
{
id: 'dept',
title: '부서',
kind: 'select',
width: 110,
editorOptions: [
{ value: 'dev', label: '개발' },
{ value: 'ops', label: '운영' },
],
optionLabel: (v) => (v === 'dev' ? '개발' : '운영'),
},
{ id: 'joined', title: '입사일', kind: 'date', width: 110 },
{ id: 'active', title: '재직', kind: 'boolean', width: 70 },
{
id: 'tags',
title: '태그',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: '알파' },
{ value: 'b', label: '베타' },
],
},
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log({
ko: 'api.exportXml()은 UTF-8 선언 아래 <rows><row>…</row></rows>를 만들어요. 글자는 모두 이스케이프돼요.',
en: 'api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.',
});
}
/** 기록은 위가 최신이라 거꾸로 적어야 위에서 아래로 읽혀요. */
function show(text: string): void {
for (const line of text.split('\n').reverse()) say(line);
}
export const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say({
ko: '이름의 < & 는 < &로, 빈 태그는 <tags/>로 나와요.',
en: 'The < and & in a name become < and &, and empty tags give <tags/>.',
});
},
custom: () => {
show(
ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'',
);
say({
ko: 'root·rowTag로 요소 이름을 바꾸고 pretty: false로 한 줄이에요.',
en: 'root and rowTag rename the elements and pretty: false gives one line.',
});
},
roundtrip: (api: GridApi<Row>) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say({
ko: `다시 읽으면 ${back?.rows.length}행, 건너뜀 ${back?.skipped}, 알림 ${back?.errors.length}건이에요. 내보낸 XML은 그대로 읽혀요.`,
en: `Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`,
});
api.getRowCount();
},
}; 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="xml">Show XML</button>
<button type="button" id="custom">Rename elements</button>
<button type="button" id="roundtrip">Read it back</button>
</div>
<div id="grid" style="height: 300px"></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('xml').addEventListener('click', () => actions.xml(api));
document.getElementById('custom').addEventListener('click', () => actions.custom(api));
document.getElementById('roundtrip').addEventListener('click', () => actions.roundtrip(api));import { withExport } from '@maxgrid/export';
const rows = [
{ id: 1, name: 'Liam Carter', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: 'Noah Kim <Lead>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{
id: 3,
name: 'Ava Brooks & Mia Young',
dept: 'dev',
joined: '2025-01-15',
active: true,
tags: ['b'],
},
];
export const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 170 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 130,
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 110 },
{ id: 'active', title: 'Active', kind: 'boolean', width: 70 },
{
id: 'tags',
title: 'Tags',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: 'Alpha' },
{ value: 'b', label: 'Beta' },
],
},
],
rows,
rowKey: 'id',
};
let say = () => { };
let ex;
export function setup(api, log) {
say = log;
ex = withExport(api);
log('api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.');
}
/** The log shows the newest line on top, so write in reverse to read top to bottom. */
function show(text) {
for (const line of text.split('\n').reverse())
say(line);
}
export const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say('The < and & in a name become < and &, and empty tags give <tags/>.');
},
custom: () => {
show(ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'');
say('root and rowTag rename the elements and pretty: false gives one line.');
},
roundtrip: (api) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say(`Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`);
api.getRowCount();
},
};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>Export the visible rows as XML</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="xml">Show XML</button>
<button type="button" id="custom">Rename elements</button>
<button type="button" id="roundtrip">Read it back</button>
</div>
<div id="grid" style="height: 300px"></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;
const rows = [
{ id: 1, name: 'Liam Carter', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: 'Noah Kim <Lead>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{
id: 3,
name: 'Ava Brooks & Mia Young',
dept: 'dev',
joined: '2025-01-15',
active: true,
tags: ['b'],
},
];
const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 170 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 130,
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 110 },
{ id: 'active', title: 'Active', kind: 'boolean', width: 70 },
{
id: 'tags',
title: 'Tags',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: 'Alpha' },
{ value: 'b', label: 'Beta' },
],
},
],
rows,
rowKey: 'id',
};
let say = () => { };
let ex;
function setup(api, log) {
say = log;
ex = withExport(api);
log('api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.');
}
/** The log shows the newest line on top, so write in reverse to read top to bottom. */
function show(text) {
for (const line of text.split('\n').reverse())
say(line);
}
const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say('The < and & in a name become < and &, and empty tags give <tags/>.');
},
custom: () => {
show(ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'');
say('root and rowTag rename the elements and pretty: false gives one line.');
},
roundtrip: (api) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say(`Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`);
api.getRowCount();
},
};
options.ariaLabel = "Export the visible rows as XML";
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('xml').addEventListener('click', () => actions.xml(api));
document.getElementById('custom').addEventListener('click', () => actions.custom(api));
document.getElementById('roundtrip').addEventListener('click', () => actions.roundtrip(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.xml(api)}
>Show XML</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.custom(api)}
>Rename elements</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.roundtrip(api)}
>Read it back</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import { withExport, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
dept: string;
joined: string;
active: boolean;
tags: string[];
}
const rows: Row[] = [
{ id: 1, name: 'Liam Carter', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: 'Noah Kim <Lead>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{
id: 3,
name: 'Ava Brooks & Mia Young',
dept: 'dev',
joined: '2025-01-15',
active: true,
tags: ['b'],
},
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 170 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 130,
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 110 },
{ id: 'active', title: 'Active', kind: 'boolean', width: 70 },
{
id: 'tags',
title: 'Tags',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: 'Alpha' },
{ value: 'b', label: 'Beta' },
],
},
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log(
'api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.',
);
}
/** The log shows the newest line on top, so write in reverse to read top to bottom. */
function show(text: string): void {
for (const line of text.split('\n').reverse()) say(line);
}
export const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say('The < and & in a name become < and &, and empty tags give <tags/>.');
},
custom: () => {
show(
ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'',
);
say('root and rowTag rename the elements and pretty: false gives one line.');
},
roundtrip: (api: GridApi<Row>) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say(
`Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`,
);
api.getRowCount();
},
}; 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.xml(api)">Show XML</button>
<button type="button" :disabled="!api" @click="api && actions.custom(api)">Rename elements</button>
<button
type="button"
:disabled="!api"
@click="api && actions.roundtrip(api)"
>Read it back</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import { withExport, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
dept: string;
joined: string;
active: boolean;
tags: string[];
}
const rows: Row[] = [
{ id: 1, name: 'Liam Carter', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: 'Noah Kim <Lead>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{
id: 3,
name: 'Ava Brooks & Mia Young',
dept: 'dev',
joined: '2025-01-15',
active: true,
tags: ['b'],
},
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 170 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 130,
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 110 },
{ id: 'active', title: 'Active', kind: 'boolean', width: 70 },
{
id: 'tags',
title: 'Tags',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: 'Alpha' },
{ value: 'b', label: 'Beta' },
],
},
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log(
'api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.',
);
}
/** The log shows the newest line on top, so write in reverse to read top to bottom. */
function show(text: string): void {
for (const line of text.split('\n').reverse()) say(line);
}
export const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say('The < and & in a name become < and &, and empty tags give <tags/>.');
},
custom: () => {
show(
ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'',
);
say('root and rowTag rename the elements and pretty: false gives one line.');
},
roundtrip: (api: GridApi<Row>) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say(
`Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`,
);
api.getRowCount();
},
}; 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.xml(api)"
>Show XML</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.custom(api)"
>Rename elements</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.roundtrip(api)"
>Read it back</button>
</div>
<mx-grid style="height: 300px" [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, type ExportableGridApi } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
name: string;
dept: string;
joined: string;
active: boolean;
tags: string[];
}
const rows: Row[] = [
{ id: 1, name: 'Liam Carter', dept: 'dev', joined: '2024-03-02', active: true, tags: ['a', 'b'] },
{ id: 2, name: 'Noah Kim <Lead>', dept: 'ops', joined: '2023-11-20', active: false, tags: [] },
{
id: 3,
name: 'Ava Brooks & Mia Young',
dept: 'dev',
joined: '2025-01-15',
active: true,
tags: ['b'],
},
];
export const options: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'name', title: 'Name', width: 170 },
{
id: 'dept',
title: 'Department',
kind: 'select',
width: 130,
editorOptions: [
{ value: 'dev', label: 'Development' },
{ value: 'ops', label: 'Operations' },
],
optionLabel: (v) => (v === 'dev' ? 'Development' : 'Operations'),
},
{ id: 'joined', title: 'Joined', kind: 'date', width: 110 },
{ id: 'active', title: 'Active', kind: 'boolean', width: 70 },
{
id: 'tags',
title: 'Tags',
width: 110,
cellEditor: 'multiselect',
editorOptions: [
{ value: 'a', label: 'Alpha' },
{ value: 'b', label: 'Beta' },
],
},
],
rows,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
let ex: ExportableGridApi<Row> | undefined;
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
ex = withExport(api);
log(
'api.exportXml() writes <rows><row>…</row></rows> under a UTF-8 declaration. All text is escaped.',
);
}
/** The log shows the newest line on top, so write in reverse to read top to bottom. */
function show(text: string): void {
for (const line of text.split('\n').reverse()) say(line);
}
export const actions = {
xml: () => {
show(ex?.exportXml({ columns: ['id', 'name', 'tags'] }) ?? '');
say('The < and & in a name become < and &, and empty tags give <tags/>.');
},
custom: () => {
show(
ex?.exportXml({ root: 'staff', rowTag: 'person', pretty: false, columns: ['id', 'name'] }) ??
'',
);
say('root and rowTag rename the elements and pretty: false gives one line.');
},
roundtrip: (api: GridApi<Row>) => {
const text = ex?.exportXml() ?? '';
const back = ex?.importXml(text);
say(
`Reading it back gives ${back?.rows.length} rows, ${back?.skipped} skipped and ${back?.errors.length} notices. The exported XML reads back as it is.`,
);
api.getRowCount();
},
};