본문으로 건너뛰기Skip to content
예제 첫화면Examples home

내보낼 컬럼·머리글·구분 글자 정하기Choose columns, header row and delimiter

숨긴 컬럼을 넣을지, 머리글 줄을 쓸지, 쉼표·탭·세미콜론 중 무엇으로 나눌지 정해서 CSV 내용을 미리 보고 내려받아요.Decide whether hidden columns and the header row are included and which delimiter separates fields, preview the text, then download.

입문Beginner
직접 써 보기Live preview내보낼 컬럼·머리글·구분 글자 정하기Choose columns, header row and delimiter

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/export로 설치하세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="숨긴 컬럼" id="hidden">
      <option value="no" selected>빼기</option>
      <option value="yes">넣기</option>
    </select>
    <select aria-label="머리글 줄" id="header">
      <option value="yes" selected>넣기</option>
      <option value="no">빼기</option>
    </select>
    <select aria-label="구분 글자" id="delimiter">
      <option value="comma" selected>쉼표(,)</option>
      <option value="tab">탭</option>
      <option value="semi">세미콜론(;)</option>
    </select>
    <button type="button" id="preview">미리 보기</button>
    <button type="button" id="download">내려받기</button>
  </div>
  <div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('hidden').addEventListener('change', (event) => actions.hidden(api, event.target.value));
document.getElementById('header').addEventListener('change', (event) => actions.header(api, event.target.value));
document.getElementById('delimiter').addEventListener('change', (event) => actions.delimiter(api, event.target.value));
document.getElementById('preview').addEventListener('click', () => actions.preview(api));
document.getElementById('download').addEventListener('click', () => actions.download(api));
example.js
import { withExport } from '@maxgrid/export';
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통', '새벽식자재'];
const regions = ['서울', '부산', '대전', '광주'];
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),
}));
// 숨긴 컬럼, 머리글 줄, 구분 글자를 정해서 내보내요. 메모 컬럼은 화면에서 숨겨 두었어요.
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 },
    { id: 'memo', title: '메모', width: 140, hidden: true },
  ],
  rows: rows.map((r) => ({ ...r, memo: r.qty > 20 ? '대량 주문' : '' })),
  rowKey: 'id',
};
let hidden = false;
let header = true;
let delimiter = ',';
let say = () => { };
export function setup(api, log) {
  say = log;
  withExport(api);
}
const options2 = () => ({
  includeHidden: hidden,
  header,
  delimiter,
  bom: false,
  newline: '\n',
});
export const actions = {
  hidden: (_api, value) => void (hidden = value === 'yes'),
  header: (_api, value) => void (header = value !== 'no'),
  delimiter: (_api, value) => void (delimiter = value === 'tab' ? '\t' : value === 'semi' ? ';' : ','),
  preview: (api) => {
    const text = withExport(api).exportCsv(options2());
    text
      .split('\n')
      .slice(0, 4)
      .reverse() // 기록은 위가 최신이라, 거꾸로 적어야 위에서 아래로 읽혀요
      .forEach((line) => say(line));
  },
  download: (api) => void withExport(api).downloadCsv('주문-컬럼선택.csv', { ...options2(), bom: true }),
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

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.

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="Hidden columns" id="hidden">
      <option value="no" selected>Exclude</option>
      <option value="yes">Include</option>
    </select>
    <select aria-label="Header row" id="header">
      <option value="yes" selected>Include</option>
      <option value="no">Exclude</option>
    </select>
    <select aria-label="Delimiter" id="delimiter">
      <option value="comma" selected>Comma</option>
      <option value="tab">Tab</option>
      <option value="semi">Semicolon</option>
    </select>
    <button type="button" id="preview">Preview</button>
    <button type="button" id="download">Download</button>
  </div>
  <div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('hidden').addEventListener('change', (event) => actions.hidden(api, event.target.value));
document.getElementById('header').addEventListener('change', (event) => actions.header(api, event.target.value));
document.getElementById('delimiter').addEventListener('change', (event) => actions.delimiter(api, event.target.value));
document.getElementById('preview').addEventListener('click', () => actions.preview(api));
document.getElementById('download').addEventListener('click', () => actions.download(api));
example.js
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'];
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),
}));
// Export with a chosen set of hidden columns, a header row and a delimiter. The memo column is hidden on screen.
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 },
    { id: 'memo', title: 'Memo', width: 140, hidden: true },
  ],
  rows: rows.map((r) => ({ ...r, memo: r.qty > 20 ? 'Bulk order' : '' })),
  rowKey: 'id',
};
let hidden = false;
let header = true;
let delimiter = ',';
let say = () => { };
export function setup(api, log) {
  say = log;
  withExport(api);
}
const options2 = () => ({
  includeHidden: hidden,
  header,
  delimiter,
  bom: false,
  newline: '\n',
});
export const actions = {
  hidden: (_api, value) => void (hidden = value === 'yes'),
  header: (_api, value) => void (header = value !== 'no'),
  delimiter: (_api, value) => void (delimiter = value === 'tab' ? '\t' : value === 'semi' ? ';' : ','),
  preview: (api) => {
    const text = withExport(api).exportCsv(options2());
    text
      .split('\n')
      .slice(0, 4)
      .reverse() // The log shows the newest line on top, so write in reverse to read top to bottom
      .forEach((line) => say(line));
  },
  download: (api) => void withExport(api).downloadCsv('orders-columns.csv', { ...options2(), bom: true }),
};