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

여유 있는 밀도(spacious)The spacious density

density: 'spacious'는 행 48px·머리글 52px·여백 16px에 줄무늬 없이, 세로선은 그대로 두고 둥근 틀과 옅은 그림자로 그려요. 다른 밀도는 그대로예요.density: 'spacious' draws 48px rows, a 52px header and 16px padding, with no stripes and the column lines kept, in a rounded frame with a soft shadow. The other densities are unchanged.

입문Beginner
직접 써 보기Live preview여유 있는 밀도(spacious)The spacious density

코드Code

탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.

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

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

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="밀도" id="density">
      <option value="compact">촘촘하게</option>
      <option value="normal">보통</option>
      <option value="comfortable">넉넉하게</option>
      <option value="spacious" selected>여유 있게</option>
    </select>
  </div>
  <div id="grid" style="height: 420px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('density').addEventListener('change', (event) => actions.density(api, event.target.value));
example.js
// 영어 페이지는 컬럼 제목과 데이터도 영어로 보여요.
const en = document.documentElement.dataset.lang === 'en';
const names = en
  ? ['Alex', 'Blair', 'Casey', 'Drew', 'Emery', 'Finn', 'Gray', 'Harper']
  : ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '김서윤'];
const depts = en
  ? ['Dev', 'Design', 'Sales', 'People']
  : ['개발팀', '디자인팀', '영업팀', '인사팀'];
export const options = {
  columns: [
    { id: 'name', title: en ? 'Name' : '이름', width: 150 },
    { id: 'dept', title: en ? 'Team' : '부서', width: 140 },
    {
      id: 'salary',
      title: en ? 'Pay' : '월급(만원)',
      kind: 'number',
      width: 130,
      align: 'end',
      formatValue: (value) => Number(value).toLocaleString(en ? 'en-US' : 'ko-KR'),
    },
  ],
  rows: names.map((name, i) => ({
    id: i + 1,
    name,
    dept: depts[i % 4],
    salary: 320 + i * 41,
  })),
  rowKey: 'id',
  // spacious: 행 48px·머리글 52px·여백 16px, 세로선은 그대로 두고 둥근 틀에 옅은 그림자를 더해요.
  density: 'spacious',
};
export const actions = {
  // 밀도만 바꿔요. 행·머리글 높이는 spacious일 때만 기본값이 커져요(rowHeight를 주면 그 값이 이겨요).
  density: (api, value) => {
    if (value === 'compact' ||
      value === 'normal' ||
      value === 'comfortable' ||
      value === 'spacious')
      api.setOptions({ density: value });
  },
};

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">
    <select aria-label="Density" id="density">
      <option value="compact">Compact</option>
      <option value="normal">Normal</option>
      <option value="comfortable">Comfortable</option>
      <option value="spacious" selected>Spacious</option>
    </select>
  </div>
  <div id="grid" style="height: 420px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('density').addEventListener('change', (event) => actions.density(api, event.target.value));
example.js
const names = ['Alex', 'Blair', 'Casey', 'Drew', 'Emery', 'Finn', 'Gray', 'Harper'];
const depts = ['Dev', 'Design', 'Sales', 'People'];
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 150 },
    { id: 'dept', title: 'Team', width: 140 },
    {
      id: 'salary',
      title: 'Pay',
      kind: 'number',
      width: 130,
      align: 'end',
      formatValue: (value) => Number(value).toLocaleString('en-US'),
    },
  ],
  rows: names.map((name, i) => ({
    id: i + 1,
    name,
    dept: depts[i % 4],
    salary: 320 + i * 41,
  })),
  rowKey: 'id',
  // spacious: 48px rows, 52px header, 16px padding; vertical lines stay and a soft shadow is added to the rounded frame.
  density: 'spacious',
};
export const actions = {
  // Change only the density. Row and header heights get larger defaults only for spacious (an explicit rowHeight wins).
  density: (api, value) => {
    if (value === 'compact' ||
      value === 'normal' ||
      value === 'comfortable' ||
      value === 'spacious')
      api.setOptions({ density: value });
  },
};