CSV로 내보내기: 전체·보이는 줄·고른 줄Export CSV: all, visible or selected rows
지역 필터를 걸고 몇 줄을 체크한 뒤, 전체·보이는 줄·고른 줄을 각각 CSV로 내려받아요. 세 파일의 줄 수가 달라요.Filter by region, tick a few rows, then download all, visible or selected rows. The three files have different row counts.
코드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">
<select aria-label="지역" id="region">
<option value="all" selected>전체 지역</option>
<option value="seoul">서울</option>
<option value="busan">부산</option>
<option value="daejeon">대전</option>
<option value="gwangju">광주</option>
</select>
<button type="button" id="all">전체 내려받기</button>
<button type="button" id="visible">보이는 줄 내려받기</button>
<button type="button" id="selected">고른 줄 내려받기</button>
</div>
<div id="grid" style="height: 330px"></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('region').addEventListener('change', (event) => actions.region(api, event.target.value));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('selected').addEventListener('click', () => actions.selected(api));import { withExport } from '@maxgrid/export';
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통', '새벽식자재'];
const regions = ['서울', '부산', '대전', '광주'];
// 지역 선택 목록은 영문 id를 넘겨요. 표에 쓰는 지역 이름으로 바꿔요.
const regionById = {
seoul: '서울',
busan: '부산',
daejeon: '대전',
gwangju: '광주',
};
const rows = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length],
region: regions[i % regions.length],
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// 내보낼 줄은 세 가지로 고를 수 있어요. 'all'은 데이터 전체, 'visible'은 정렬·필터를 거친 보이는 줄,
// 'selected'는 체크한 줄만이에요.
export const options = {
columns: [
{ id: 'orderNo', title: '주문번호', width: 100 },
{ id: 'customer', title: '거래처', width: 110 },
{ id: 'region', title: '지역', width: 70 },
{ id: 'qty', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '단가(원)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('ko-KR'),
},
{ id: 'orderedAt', title: '주문일', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
export function setup(api, log) {
say = log;
withExport(api); // 그리드 api에 exportCsv·downloadCsv 같은 내보내기 메서드를 붙여요.
log({
ko: '지역을 거르고 몇 줄을 체크한 뒤 세 버튼을 눌러 보세요.',
en: 'Filter by region, check a few rows, then press the three buttons.',
});
}
function run(api, scope, file) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // 머리글 줄 빼기
if (lines === 0)
return say({
ko: scope === 'selected' ? '체크한 줄이 없어요.' : '내보낼 줄이 없어요.',
en: scope === 'selected' ? 'No rows are checked.' : 'No rows to export.',
});
void ex.downloadCsv(file, { rowScope: scope });
say({ ko: `${file}: ${lines}줄을 내려받아요.`, en: `${file}: downloading ${lines} rows.` });
}
export const actions = {
region: (api, value) => api.setFilterModel(value && value !== 'all'
? {
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: regionById[value] ?? value }],
}
: null),
all: (api) => run(api, 'all', '주문-전체.csv'),
visible: (api) => run(api, 'visible', '주문-보이는줄.csv'),
selected: (api) => run(api, 'selected', '주문-고른줄.csv'),
}; 이 HTML은 추가 번들(위 script 태그)도 함께 불러오고 전역 변수로 써요. 별도 설치는 필요 없어요.
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>CSV로 내보내기: 전체·보이는 줄·고른 줄</title>
</head>
<body>
<div class="toolbar">
<select aria-label="지역" id="region">
<option value="all" selected>전체 지역</option>
<option value="seoul">서울</option>
<option value="busan">부산</option>
<option value="daejeon">대전</option>
<option value="gwangju">광주</option>
</select>
<button type="button" id="all">전체 내려받기</button>
<button type="button" id="visible">보이는 줄 내려받기</button>
<button type="button" id="selected">고른 줄 내려받기</button>
</div>
<div id="grid" style="height: 330px"></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 customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통', '새벽식자재'];
const regions = ['서울', '부산', '대전', '광주'];
// 지역 선택 목록은 영문 id를 넘겨요. 표에 쓰는 지역 이름으로 바꿔요.
const regionById = {
seoul: '서울',
busan: '부산',
daejeon: '대전',
gwangju: '광주',
};
const rows = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length],
region: regions[i % regions.length],
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// 내보낼 줄은 세 가지로 고를 수 있어요. 'all'은 데이터 전체, 'visible'은 정렬·필터를 거친 보이는 줄,
// 'selected'는 체크한 줄만이에요.
const options = {
columns: [
{ id: 'orderNo', title: '주문번호', width: 100 },
{ id: 'customer', title: '거래처', width: 110 },
{ id: 'region', title: '지역', width: 70 },
{ id: 'qty', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '단가(원)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('ko-KR'),
},
{ id: 'orderedAt', title: '주문일', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
function setup(api, log) {
say = log;
withExport(api); // 그리드 api에 exportCsv·downloadCsv 같은 내보내기 메서드를 붙여요.
log({
ko: '지역을 거르고 몇 줄을 체크한 뒤 세 버튼을 눌러 보세요.',
en: 'Filter by region, check a few rows, then press the three buttons.',
});
}
function run(api, scope, file) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // 머리글 줄 빼기
if (lines === 0)
return say({
ko: scope === 'selected' ? '체크한 줄이 없어요.' : '내보낼 줄이 없어요.',
en: scope === 'selected' ? 'No rows are checked.' : 'No rows to export.',
});
void ex.downloadCsv(file, { rowScope: scope });
say({ ko: `${file}: ${lines}줄을 내려받아요.`, en: `${file}: downloading ${lines} rows.` });
}
const actions = {
region: (api, value) => api.setFilterModel(value && value !== 'all'
? {
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: regionById[value] ?? value }],
}
: null),
all: (api) => run(api, 'all', '주문-전체.csv'),
visible: (api) => run(api, 'visible', '주문-보이는줄.csv'),
selected: (api) => run(api, 'selected', '주문-고른줄.csv'),
};
options.ariaLabel = "CSV로 내보내기: 전체·보이는 줄·고른 줄";
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('region').addEventListener('change', (event) => actions.region(api, event.target.value));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('selected').addEventListener('click', () => actions.selected(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">
<select
aria-label="지역"
disabled={!api}
onChange={(event) => api && actions.region(api, event.target.value)}
>
<option value="all">전체 지역</option>
<option value="seoul">서울</option>
<option value="busan">부산</option>
<option value="daejeon">대전</option>
<option value="gwangju">광주</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>전체 내려받기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.visible(api)}
>보이는 줄 내려받기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.selected(api)}
>고른 줄 내려받기</button>
</div>
<Grid style={{ height: 330 }} 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;
orderNo: string;
customer: string;
region: string;
qty: number;
price: number;
orderedAt: Date;
}
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통', '새벽식자재'];
const regions = ['서울', '부산', '대전', '광주'];
// 지역 선택 목록은 영문 id를 넘겨요. 표에 쓰는 지역 이름으로 바꿔요.
const regionById: Record<string, string> = {
seoul: '서울',
busan: '부산',
daejeon: '대전',
gwangju: '광주',
};
const rows: Row[] = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length] as string,
region: regions[i % regions.length] as string,
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// 내보낼 줄은 세 가지로 고를 수 있어요. 'all'은 데이터 전체, 'visible'은 정렬·필터를 거친 보이는 줄,
// 'selected'는 체크한 줄만이에요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'orderNo', title: '주문번호', width: 100 },
{ id: 'customer', title: '거래처', width: 110 },
{ id: 'region', title: '지역', width: 70 },
{ id: 'qty', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '단가(원)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('ko-KR'),
},
{ id: 'orderedAt', title: '주문일', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api); // 그리드 api에 exportCsv·downloadCsv 같은 내보내기 메서드를 붙여요.
log({
ko: '지역을 거르고 몇 줄을 체크한 뒤 세 버튼을 눌러 보세요.',
en: 'Filter by region, check a few rows, then press the three buttons.',
});
}
function run(api: GridApi<Row>, scope: 'all' | 'visible' | 'selected', file: string) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // 머리글 줄 빼기
if (lines === 0)
return say({
ko: scope === 'selected' ? '체크한 줄이 없어요.' : '내보낼 줄이 없어요.',
en: scope === 'selected' ? 'No rows are checked.' : 'No rows to export.',
});
void ex.downloadCsv(file, { rowScope: scope });
say({ ko: `${file}: ${lines}줄을 내려받아요.`, en: `${file}: downloading ${lines} rows.` });
}
export const actions = {
region: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && value !== 'all'
? {
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: regionById[value] ?? value }],
}
: null,
),
all: (api: GridApi<Row>) => run(api, 'all', '주문-전체.csv'),
visible: (api: GridApi<Row>) => run(api, 'visible', '주문-보이는줄.csv'),
selected: (api: GridApi<Row>) => run(api, 'selected', '주문-고른줄.csv'),
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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">
<select
aria-label="지역"
:disabled="!api"
@change="api && actions.region(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>전체 지역</option>
<option value="seoul">서울</option>
<option value="busan">부산</option>
<option value="daejeon">대전</option>
<option value="gwangju">광주</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.all(api)">전체 내려받기</button>
<button type="button" :disabled="!api" @click="api && actions.visible(api)">보이는 줄 내려받기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.selected(api)"
>고른 줄 내려받기</button>
</div>
<Grid style="height: 330px" :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;
orderNo: string;
customer: string;
region: string;
qty: number;
price: number;
orderedAt: Date;
}
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통', '새벽식자재'];
const regions = ['서울', '부산', '대전', '광주'];
// 지역 선택 목록은 영문 id를 넘겨요. 표에 쓰는 지역 이름으로 바꿔요.
const regionById: Record<string, string> = {
seoul: '서울',
busan: '부산',
daejeon: '대전',
gwangju: '광주',
};
const rows: Row[] = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length] as string,
region: regions[i % regions.length] as string,
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// 내보낼 줄은 세 가지로 고를 수 있어요. 'all'은 데이터 전체, 'visible'은 정렬·필터를 거친 보이는 줄,
// 'selected'는 체크한 줄만이에요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'orderNo', title: '주문번호', width: 100 },
{ id: 'customer', title: '거래처', width: 110 },
{ id: 'region', title: '지역', width: 70 },
{ id: 'qty', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '단가(원)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('ko-KR'),
},
{ id: 'orderedAt', title: '주문일', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api); // 그리드 api에 exportCsv·downloadCsv 같은 내보내기 메서드를 붙여요.
log({
ko: '지역을 거르고 몇 줄을 체크한 뒤 세 버튼을 눌러 보세요.',
en: 'Filter by region, check a few rows, then press the three buttons.',
});
}
function run(api: GridApi<Row>, scope: 'all' | 'visible' | 'selected', file: string) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // 머리글 줄 빼기
if (lines === 0)
return say({
ko: scope === 'selected' ? '체크한 줄이 없어요.' : '내보낼 줄이 없어요.',
en: scope === 'selected' ? 'No rows are checked.' : 'No rows to export.',
});
void ex.downloadCsv(file, { rowScope: scope });
say({ ko: `${file}: ${lines}줄을 내려받아요.`, en: `${file}: downloading ${lines} rows.` });
}
export const actions = {
region: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && value !== 'all'
? {
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: regionById[value] ?? value }],
}
: null,
),
all: (api: GridApi<Row>) => run(api, 'all', '주문-전체.csv'),
visible: (api: GridApi<Row>) => run(api, 'visible', '주문-보이는줄.csv'),
selected: (api: GridApi<Row>) => run(api, 'selected', '주문-고른줄.csv'),
}; 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 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">
<select
aria-label="지역"
[disabled]="!api"
(change)="api && actions.region(api, $any($event.target).value)"
>
<option value="all" selected>전체 지역</option>
<option value="seoul">서울</option>
<option value="busan">부산</option>
<option value="daejeon">대전</option>
<option value="gwangju">광주</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>전체 내려받기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.visible(api)"
>보이는 줄 내려받기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.selected(api)"
>고른 줄 내려받기</button>
</div>
<mx-grid style="height: 330px" [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;
orderNo: string;
customer: string;
region: string;
qty: number;
price: number;
orderedAt: Date;
}
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통', '새벽식자재'];
const regions = ['서울', '부산', '대전', '광주'];
// 지역 선택 목록은 영문 id를 넘겨요. 표에 쓰는 지역 이름으로 바꿔요.
const regionById: Record<string, string> = {
seoul: '서울',
busan: '부산',
daejeon: '대전',
gwangju: '광주',
};
const rows: Row[] = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length] as string,
region: regions[i % regions.length] as string,
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// 내보낼 줄은 세 가지로 고를 수 있어요. 'all'은 데이터 전체, 'visible'은 정렬·필터를 거친 보이는 줄,
// 'selected'는 체크한 줄만이에요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'orderNo', title: '주문번호', width: 100 },
{ id: 'customer', title: '거래처', width: 110 },
{ id: 'region', title: '지역', width: 70 },
{ id: 'qty', title: '수량', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: '단가(원)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('ko-KR'),
},
{ id: 'orderedAt', title: '주문일', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api); // 그리드 api에 exportCsv·downloadCsv 같은 내보내기 메서드를 붙여요.
log({
ko: '지역을 거르고 몇 줄을 체크한 뒤 세 버튼을 눌러 보세요.',
en: 'Filter by region, check a few rows, then press the three buttons.',
});
}
function run(api: GridApi<Row>, scope: 'all' | 'visible' | 'selected', file: string) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // 머리글 줄 빼기
if (lines === 0)
return say({
ko: scope === 'selected' ? '체크한 줄이 없어요.' : '내보낼 줄이 없어요.',
en: scope === 'selected' ? 'No rows are checked.' : 'No rows to export.',
});
void ex.downloadCsv(file, { rowScope: scope });
say({ ko: `${file}: ${lines}줄을 내려받아요.`, en: `${file}: downloading ${lines} rows.` });
}
export const actions = {
region: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && value !== 'all'
? {
match: 'all',
items: [{ columnId: 'region', operator: 'equals', value: regionById[value] ?? value }],
}
: null,
),
all: (api: GridApi<Row>) => run(api, 'all', '주문-전체.csv'),
visible: (api: GridApi<Row>) => run(api, 'visible', '주문-보이는줄.csv'),
selected: (api: GridApi<Row>) => run(api, 'selected', '주문-고른줄.csv'),
}; 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">
<select aria-label="Region" id="region">
<option value="all" selected>All regions</option>
<option value="seoul">Seoul</option>
<option value="busan">Busan</option>
<option value="daejeon">Daejeon</option>
<option value="gwangju">Gwangju</option>
</select>
<button type="button" id="all">Download all</button>
<button type="button" id="visible">Download visible</button>
<button type="button" id="selected">Download selected</button>
</div>
<div id="grid" style="height: 330px"></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('region').addEventListener('change', (event) => actions.region(api, event.target.value));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('selected').addEventListener('click', () => actions.selected(api));import { withExport } from '@maxgrid/export';
const customers = [
'Harbor Foods',
'Pine Hardware',
'Blue Market',
'Maple Trading',
'Ocean Supply',
'Dawn Grocers',
];
const regions = ['Seoul', 'Busan', 'Daejeon', 'Gwangju'];
// The region control (meta.json) passes ASCII ids. Map them to the region names used in the table.
const regionById = {
seoul: 'Seoul',
busan: 'Busan',
daejeon: 'Daejeon',
gwangju: 'Gwangju',
};
const rows = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length],
region: regions[i % regions.length],
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// Rows to export can be chosen in three ways. 'all' is every row, 'visible' is the rows left after sort and filter,
// 'selected' is only the checked rows.
export const options = {
columns: [
{ id: 'orderNo', title: 'Order no.', width: 100 },
{ id: 'customer', title: 'Customer', width: 110 },
{ id: 'region', title: 'Region', width: 80 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('en-US'),
},
{ id: 'orderedAt', title: 'Ordered', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
export function setup(api, log) {
say = log;
withExport(api); // Attach export methods such as exportCsv and downloadCsv to the grid api.
log('Filter by region, check a few rows, then press the three buttons.');
}
function run(api, scope, file) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // Exclude the header line
if (lines === 0)
return say(scope === 'selected' ? 'No rows are checked.' : 'No rows to export.');
void ex.downloadCsv(file, { rowScope: scope });
say(`${file}: downloading ${lines} rows.`);
}
export const actions = {
region: (api, value) => api.setFilterModel(value && value !== 'all'
? {
match: 'all',
items: [
{
columnId: 'region',
operator: 'equals',
value: regionById[value] ?? value,
},
],
}
: null),
all: (api) => run(api, 'all', 'orders-all.csv'),
visible: (api) => run(api, 'visible', 'orders-visible.csv'),
selected: (api) => run(api, 'selected', 'orders-selected.csv'),
};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 CSV: all, visible or selected rows</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Region" id="region">
<option value="all" selected>All regions</option>
<option value="seoul">Seoul</option>
<option value="busan">Busan</option>
<option value="daejeon">Daejeon</option>
<option value="gwangju">Gwangju</option>
</select>
<button type="button" id="all">Download all</button>
<button type="button" id="visible">Download visible</button>
<button type="button" id="selected">Download selected</button>
</div>
<div id="grid" style="height: 330px"></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 customers = [
'Harbor Foods',
'Pine Hardware',
'Blue Market',
'Maple Trading',
'Ocean Supply',
'Dawn Grocers',
];
const regions = ['Seoul', 'Busan', 'Daejeon', 'Gwangju'];
// The region control (meta.json) passes ASCII ids. Map them to the region names used in the table.
const regionById = {
seoul: 'Seoul',
busan: 'Busan',
daejeon: 'Daejeon',
gwangju: 'Gwangju',
};
const rows = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length],
region: regions[i % regions.length],
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// Rows to export can be chosen in three ways. 'all' is every row, 'visible' is the rows left after sort and filter,
// 'selected' is only the checked rows.
const options = {
columns: [
{ id: 'orderNo', title: 'Order no.', width: 100 },
{ id: 'customer', title: 'Customer', width: 110 },
{ id: 'region', title: 'Region', width: 80 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('en-US'),
},
{ id: 'orderedAt', title: 'Ordered', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say = () => { };
function setup(api, log) {
say = log;
withExport(api); // Attach export methods such as exportCsv and downloadCsv to the grid api.
log('Filter by region, check a few rows, then press the three buttons.');
}
function run(api, scope, file) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // Exclude the header line
if (lines === 0)
return say(scope === 'selected' ? 'No rows are checked.' : 'No rows to export.');
void ex.downloadCsv(file, { rowScope: scope });
say(`${file}: downloading ${lines} rows.`);
}
const actions = {
region: (api, value) => api.setFilterModel(value && value !== 'all'
? {
match: 'all',
items: [
{
columnId: 'region',
operator: 'equals',
value: regionById[value] ?? value,
},
],
}
: null),
all: (api) => run(api, 'all', 'orders-all.csv'),
visible: (api) => run(api, 'visible', 'orders-visible.csv'),
selected: (api) => run(api, 'selected', 'orders-selected.csv'),
};
options.ariaLabel = "Export CSV: all, visible or selected rows";
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('region').addEventListener('change', (event) => actions.region(api, event.target.value));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('selected').addEventListener('click', () => actions.selected(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">
<select
aria-label="Region"
disabled={!api}
onChange={(event) => api && actions.region(api, event.target.value)}
>
<option value="all">All regions</option>
<option value="seoul">Seoul</option>
<option value="busan">Busan</option>
<option value="daejeon">Daejeon</option>
<option value="gwangju">Gwangju</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>Download all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.visible(api)}
>Download visible</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.selected(api)}
>Download selected</button>
</div>
<Grid style={{ height: 330 }} 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;
orderNo: string;
customer: string;
region: string;
qty: number;
price: number;
orderedAt: Date;
}
const customers = [
'Harbor Foods',
'Pine Hardware',
'Blue Market',
'Maple Trading',
'Ocean Supply',
'Dawn Grocers',
];
const regions = ['Seoul', 'Busan', 'Daejeon', 'Gwangju'];
// The region control (meta.json) passes ASCII ids. Map them to the region names used in the table.
const regionById: Record<string, string> = {
seoul: 'Seoul',
busan: 'Busan',
daejeon: 'Daejeon',
gwangju: 'Gwangju',
};
const rows: Row[] = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length] as string,
region: regions[i % regions.length] as string,
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// Rows to export can be chosen in three ways. 'all' is every row, 'visible' is the rows left after sort and filter,
// 'selected' is only the checked rows.
export const options: GridOptions<Row> = {
columns: [
{ id: 'orderNo', title: 'Order no.', width: 100 },
{ id: 'customer', title: 'Customer', width: 110 },
{ id: 'region', title: 'Region', width: 80 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('en-US'),
},
{ id: 'orderedAt', title: 'Ordered', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api); // Attach export methods such as exportCsv and downloadCsv to the grid api.
log('Filter by region, check a few rows, then press the three buttons.');
}
function run(api: GridApi<Row>, scope: 'all' | 'visible' | 'selected', file: string) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // Exclude the header line
if (lines === 0) return say(scope === 'selected' ? 'No rows are checked.' : 'No rows to export.');
void ex.downloadCsv(file, { rowScope: scope });
say(`${file}: downloading ${lines} rows.`);
}
export const actions = {
region: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && value !== 'all'
? {
match: 'all',
items: [
{
columnId: 'region',
operator: 'equals',
value: regionById[value] ?? value,
},
],
}
: null,
),
all: (api: GridApi<Row>) => run(api, 'all', 'orders-all.csv'),
visible: (api: GridApi<Row>) => run(api, 'visible', 'orders-visible.csv'),
selected: (api: GridApi<Row>) => run(api, 'selected', 'orders-selected.csv'),
}; 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">
<select
aria-label="Region"
:disabled="!api"
@change="api && actions.region(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all" selected>All regions</option>
<option value="seoul">Seoul</option>
<option value="busan">Busan</option>
<option value="daejeon">Daejeon</option>
<option value="gwangju">Gwangju</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.all(api)">Download all</button>
<button type="button" :disabled="!api" @click="api && actions.visible(api)">Download visible</button>
<button
type="button"
:disabled="!api"
@click="api && actions.selected(api)"
>Download selected</button>
</div>
<Grid style="height: 330px" :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;
orderNo: string;
customer: string;
region: string;
qty: number;
price: number;
orderedAt: Date;
}
const customers = [
'Harbor Foods',
'Pine Hardware',
'Blue Market',
'Maple Trading',
'Ocean Supply',
'Dawn Grocers',
];
const regions = ['Seoul', 'Busan', 'Daejeon', 'Gwangju'];
// The region control (meta.json) passes ASCII ids. Map them to the region names used in the table.
const regionById: Record<string, string> = {
seoul: 'Seoul',
busan: 'Busan',
daejeon: 'Daejeon',
gwangju: 'Gwangju',
};
const rows: Row[] = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length] as string,
region: regions[i % regions.length] as string,
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// Rows to export can be chosen in three ways. 'all' is every row, 'visible' is the rows left after sort and filter,
// 'selected' is only the checked rows.
export const options: GridOptions<Row> = {
columns: [
{ id: 'orderNo', title: 'Order no.', width: 100 },
{ id: 'customer', title: 'Customer', width: 110 },
{ id: 'region', title: 'Region', width: 80 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('en-US'),
},
{ id: 'orderedAt', title: 'Ordered', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api); // Attach export methods such as exportCsv and downloadCsv to the grid api.
log('Filter by region, check a few rows, then press the three buttons.');
}
function run(api: GridApi<Row>, scope: 'all' | 'visible' | 'selected', file: string) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // Exclude the header line
if (lines === 0) return say(scope === 'selected' ? 'No rows are checked.' : 'No rows to export.');
void ex.downloadCsv(file, { rowScope: scope });
say(`${file}: downloading ${lines} rows.`);
}
export const actions = {
region: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && value !== 'all'
? {
match: 'all',
items: [
{
columnId: 'region',
operator: 'equals',
value: regionById[value] ?? value,
},
],
}
: null,
),
all: (api: GridApi<Row>) => run(api, 'all', 'orders-all.csv'),
visible: (api: GridApi<Row>) => run(api, 'visible', 'orders-visible.csv'),
selected: (api: GridApi<Row>) => run(api, 'selected', 'orders-selected.csv'),
}; 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">
<select
aria-label="Region"
[disabled]="!api"
(change)="api && actions.region(api, $any($event.target).value)"
>
<option value="all" selected>All regions</option>
<option value="seoul">Seoul</option>
<option value="busan">Busan</option>
<option value="daejeon">Daejeon</option>
<option value="gwangju">Gwangju</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>Download all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.visible(api)"
>Download visible</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.selected(api)"
>Download selected</button>
</div>
<mx-grid style="height: 330px" [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;
orderNo: string;
customer: string;
region: string;
qty: number;
price: number;
orderedAt: Date;
}
const customers = [
'Harbor Foods',
'Pine Hardware',
'Blue Market',
'Maple Trading',
'Ocean Supply',
'Dawn Grocers',
];
const regions = ['Seoul', 'Busan', 'Daejeon', 'Gwangju'];
// The region control (meta.json) passes ASCII ids. Map them to the region names used in the table.
const regionById: Record<string, string> = {
seoul: 'Seoul',
busan: 'Busan',
daejeon: 'Daejeon',
gwangju: 'Gwangju',
};
const rows: Row[] = Array.from({ length: 12 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${3001 + i}`,
customer: customers[i % customers.length] as string,
region: regions[i % regions.length] as string,
qty: 3 + ((i * 7) % 28),
price: 4200 + ((i * 1900) % 21000),
orderedAt: new Date(2026, 9, 1 + i * 2),
}));
// Rows to export can be chosen in three ways. 'all' is every row, 'visible' is the rows left after sort and filter,
// 'selected' is only the checked rows.
export const options: GridOptions<Row> = {
columns: [
{ id: 'orderNo', title: 'Order no.', width: 100 },
{ id: 'customer', title: 'Customer', width: 110 },
{ id: 'region', title: 'Region', width: 80 },
{ id: 'qty', title: 'Qty', kind: 'number', width: 70, align: 'end' },
{
id: 'price',
title: 'Price ($)',
kind: 'number',
width: 100,
align: 'end',
formatValue: (v) => Number(v).toLocaleString('en-US'),
},
{ id: 'orderedAt', title: 'Ordered', kind: 'date', width: 110 },
],
rows,
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
withExport(api); // Attach export methods such as exportCsv and downloadCsv to the grid api.
log('Filter by region, check a few rows, then press the three buttons.');
}
function run(api: GridApi<Row>, scope: 'all' | 'visible' | 'selected', file: string) {
const ex = withExport(api);
const lines = ex.exportCsv({ rowScope: scope }).split('\r\n').filter(Boolean).length - 1; // Exclude the header line
if (lines === 0) return say(scope === 'selected' ? 'No rows are checked.' : 'No rows to export.');
void ex.downloadCsv(file, { rowScope: scope });
say(`${file}: downloading ${lines} rows.`);
}
export const actions = {
region: (api: GridApi<Row>, value?: string) =>
api.setFilterModel(
value && value !== 'all'
? {
match: 'all',
items: [
{
columnId: 'region',
operator: 'equals',
value: regionById[value] ?? value,
},
],
}
: null,
),
all: (api: GridApi<Row>) => run(api, 'all', 'orders-all.csv'),
visible: (api: GridApi<Row>) => run(api, 'visible', 'orders-visible.csv'),
selected: (api: GridApi<Row>) => run(api, 'selected', 'orders-selected.csv'),
};