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

처음부터 모두 펼쳐서 보여 주기Start with every branch open

트리를 처음 그릴 때 모든 가지를 열어 둘 수 있어요. 펼침 화살표는 첫 컬럼이 아니라 원하는 컬럼(여기서는 "작업")에 붙일 수 있고요.The tree can start fully open. The expand arrow can sit on any column you choose, here "Task", not only the first one.

입문Beginner
직접 써 보기Live preview처음부터 모두 펼쳐서 보여 주기Start with every branch open

코드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 탭이나 직접 해보기를 쓰세요.

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

index.html
<div id="app">
  <div class="toolbar">
    <button type="button" id="expandAll">모두 열기</button>
    <button type="button" id="collapseAll">모두 닫기</button>
  </div>
  <div id="grid" style="height: 430px"></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('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
example.js
// 번호(code)가 첫 컬럼이고, 펼침 화살표는 두 번째 컬럼인 "작업"에 붙어요.
const rows = [
  { id: 'T1', parentId: null, code: 'T1', task: '출시 준비', owner: '김서연', end: '2026-12-18' },
  { id: 'T10', parentId: 'T1', code: 'T10', task: '기획', owner: '이준호', end: '2026-11-13' },
  {
    id: 'T11',
    parentId: 'T10',
    code: 'T11',
    task: '요구사항 정리',
    owner: '이준호',
    end: '2026-11-06',
  },
  {
    id: 'T12',
    parentId: 'T10',
    code: 'T12',
    task: '화면 설계',
    owner: '박민지',
    end: '2026-11-13',
  },
  { id: 'T20', parentId: 'T1', code: 'T20', task: '개발', owner: '최도윤', end: '2026-12-04' },
  {
    id: 'T21',
    parentId: 'T20',
    code: 'T21',
    task: '프런트엔드',
    owner: '정하은',
    end: '2026-11-27',
  },
  { id: 'T22', parentId: 'T20', code: 'T22', task: '백엔드', owner: '최도윤', end: '2026-12-04' },
  { id: 'T30', parentId: 'T1', code: 'T30', task: '테스트', owner: '박민지', end: '2026-12-18' },
  {
    id: 'T31',
    parentId: 'T30',
    code: 'T31',
    task: '기능 테스트',
    owner: '박민지',
    end: '2026-12-11',
  },
  {
    id: 'T32',
    parentId: 'T30',
    code: 'T32',
    task: '성능 테스트',
    owner: '임태민',
    end: '2026-12-18',
  },
  { id: 'T2', parentId: null, code: 'T2', task: '운영 준비', owner: '김서연', end: '2026-12-23' },
  {
    id: 'T40',
    parentId: 'T2',
    code: 'T40',
    task: '교육 자료 작성',
    owner: '한지우',
    end: '2026-12-11',
  },
];
export const options = {
  columns: [
    { id: 'code', title: '번호', width: 90 },
    { id: 'task', title: '작업', width: 220 },
    { id: 'owner', title: '담당자', width: 100 },
    { id: 'end', title: '종료', width: 110 },
  ],
  rows,
  rowKey: 'id',
  // column: 화살표를 붙일 컬럼(기본은 첫 컬럼). expandDepth: 'all': 처음부터 모두 펼쳐서 보여 줘요.
  tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say = () => { };
const openCount = (api) => api.getRows().filter((row) => api.isRowExpanded(row.id)).length;
export function setup(api, log) {
  say = log;
  log({
    ko: `처음부터 모든 가지가 열려 있어요. (열린 가지 ${openCount(api)}개)`,
    en: `Every branch starts open. (${openCount(api)} branches open)`,
  });
}
export const actions = {
  expandAll: (api) => {
    api.expandAll();
    say({
      ko: `모두 열었어요. 보이는 줄 ${api.getVisibleRowCount()}개`,
      en: `Opened all. ${api.getVisibleRowCount()} rows visible`,
    });
  },
  collapseAll: (api) => {
    api.collapseAll();
    say({
      ko: `모두 닫았어요. 보이는 줄 ${api.getVisibleRowCount()}개`,
      en: `Closed all. ${api.getVisibleRowCount()} rows visible`,
    });
  },
};

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

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="expandAll">Expand all</button>
    <button type="button" id="collapseAll">Collapse all</button>
  </div>
  <div id="grid" style="height: 430px"></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('expandAll').addEventListener('click', () => actions.expandAll(api));
document.getElementById('collapseAll').addEventListener('click', () => actions.collapseAll(api));
example.js
// The code is the first column, and the expand arrow sits on the second column, "Task".
const rows = [
  { id: 'T1', parentId: null, code: 'T1', task: 'Release', owner: 'Emma Stone', end: '2026-12-18' },
  {
    id: 'T10',
    parentId: 'T1',
    code: 'T10',
    task: 'Planning',
    owner: 'Liam Carter',
    end: '2026-11-13',
  },
  {
    id: 'T11',
    parentId: 'T10',
    code: 'T11',
    task: 'Gather requirements',
    owner: 'Liam Carter',
    end: '2026-11-06',
  },
  {
    id: 'T12',
    parentId: 'T10',
    code: 'T12',
    task: 'Screen design',
    owner: 'Mia Parker',
    end: '2026-11-13',
  },
  {
    id: 'T20',
    parentId: 'T1',
    code: 'T20',
    task: 'Development',
    owner: 'Noah Davis',
    end: '2026-12-04',
  },
  {
    id: 'T21',
    parentId: 'T20',
    code: 'T21',
    task: 'Frontend',
    owner: 'Ava Moore',
    end: '2026-11-27',
  },
  {
    id: 'T22',
    parentId: 'T20',
    code: 'T22',
    task: 'Backend',
    owner: 'Noah Davis',
    end: '2026-12-04',
  },
  {
    id: 'T30',
    parentId: 'T1',
    code: 'T30',
    task: 'Testing',
    owner: 'Mia Parker',
    end: '2026-12-18',
  },
  {
    id: 'T31',
    parentId: 'T30',
    code: 'T31',
    task: 'Functional test',
    owner: 'Mia Parker',
    end: '2026-12-11',
  },
  {
    id: 'T32',
    parentId: 'T30',
    code: 'T32',
    task: 'Performance test',
    owner: 'Ethan Lee',
    end: '2026-12-18',
  },
  {
    id: 'T2',
    parentId: null,
    code: 'T2',
    task: 'Operations prep',
    owner: 'Emma Stone',
    end: '2026-12-23',
  },
  {
    id: 'T40',
    parentId: 'T2',
    code: 'T40',
    task: 'Write training materials',
    owner: 'Grace Hall',
    end: '2026-12-11',
  },
];
export const options = {
  columns: [
    { id: 'code', title: 'Code', width: 90 },
    { id: 'task', title: 'Task', width: 220 },
    { id: 'owner', title: 'Owner', width: 120 },
    { id: 'end', title: 'End', width: 110 },
  ],
  rows,
  rowKey: 'id',
  // column: the column that gets the arrow (the first column by default). expandDepth: 'all' starts with everything open.
  tree: { parentKey: 'parentId', column: 'task', expandDepth: 'all' },
};
let say = () => { };
const openCount = (api) => api.getRows().filter((row) => api.isRowExpanded(row.id)).length;
export function setup(api, log) {
  say = log;
  log(`Every branch starts open. (${openCount(api)} branches open)`);
}
export const actions = {
  expandAll: (api) => {
    api.expandAll();
    say(`Opened all. ${api.getVisibleRowCount()} rows visible`);
  },
  collapseAll: (api) => {
    api.collapseAll();
    say(`Closed all. ${api.getVisibleRowCount()} rows visible`);
  },
};