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

그리드 전체의 내보내기 기본값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.

입문Beginner
직접 써 보기Live preview그리드 전체의 내보내기 기본값Grid-wide export defaults

코드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">
    <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>
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('csvDefault').addEventListener('click', () => actions.csvDefault(api));
document.getElementById('csvComma').addEventListener('click', () => actions.csvComma(api));
document.getElementById('xlsx').addEventListener('click', () => actions.xlsx(api));
example.js
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 "주문".' });
  },
};

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">
    <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>
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('csvDefault').addEventListener('click', () => actions.csvDefault(api));
document.getElementById('csvComma').addEventListener('click', () => actions.csvComma(api));
document.getElementById('xlsx').addEventListener('click', () => actions.xlsx(api));
example.js
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".');
  },
};