horee-gridb0.0.1

시작하기

설치부터 첫 그리드를 띄우기까지 5분이면 된다. 이 페이지만 따라 하면 나머지 가이드는 필요할 때 찾아보면 된다.

설치

horee-grid 는 npm 공개 저장소에 올리지 않는다. 구입하면 받는 묶음 파일(horee-grid-버전.tgz)을 프로젝트 안에 두고 설치한다.

# 받은 파일을 프로젝트의 vendor 폴더에 둔 뒤
npm install ./vendor/horee-grid-0.0.1-beta.1.tgz

package.json 에는 이렇게 남는다. 판을 올릴 때는 파일을 바꾸고 같은 명령을 다시 실행한다.

"dependencies": {
  "horee-grid": "file:vendor/horee-grid-0.0.1-beta.1.tgz"
}
같은 판 번호로 다시 받았을 때

판 번호가 같으면 npm install 만으로는 새 파일로 바뀌지 않는다. 위의 npm install ./vendor/…tgz 를 직접 실행한다.

묶음에 든 것:

파일내용
dist/horee-grid.jsES 모듈 (Vite · webpack 등 번들러용)
dist/horee-grid.umd.cjsUMD (<script> 로 넣거나 CommonJS)
dist/horee-grid.css기본 모양
dist/types/*.d.tsTypeScript 형식 정의

첫 그리드

세 가지만 있으면 된다. 높이가 있는 요소, 컬럼 정의, 행 배열.

<div id="grid" style="height: 400px"></div>
basic.js
import { createGrid } from 'horee-grid'

const grid = createGrid(host, {
  columns: [
    { field: 'code', title: '코드', width: 80 },
    { field: 'name', title: '품목명', flex: 1, minWidth: 160 },
    { field: 'qty', title: '수량', type: 'number', width: 90 },
    { field: 'price', title: '단가', type: 'number', width: 110 },
    { field: 'day', title: '입고일', type: 'date', width: 110 }
  ],
  rows: [
    { code: 'A001', name: '볼트 M8', qty: 1200, price: 85, day: '2026-11-02' },
    { code: 'A002', name: '너트 M8', qty: 1500, price: 40, day: '2026-11-02' },
    { code: 'B010', name: '베어링 6204', qty: 64, price: 5300, day: '2026-11-15' },
    { code: 'C120', name: '오일 실 35x52', qty: 210, price: 1250, day: '2026-11-21' }
  ],
  rowKey: 'code'
})
import { createGrid } from 'horee-grid'
import 'horee-grid/dist/horee-grid.css'

const grid = createGrid(document.getElementById('grid')!, { columns, rows, rowKey: 'code' })
  • createGrid(요소, 옵션) 은 Grid 객체를 돌려준다. 그 뒤로는 이 객체의 메서드로 다룬다(grid.setRows(…), grid.getSelectedRows() …).
  • 행은 그냥 객체다. 컬럼의 field 가 객체의 키다.
  • rowKey 는 행을 구별하는 필드다. 다시 조회해 행을 바꿔도 선택과 활성 칸을 유지하고, select(키) 로 행을 고를 때 쓴다. 꼭 주는 것이 좋다.
이 문서의 예제

예제 코드의 host 는 그리드를 넣을 요소, toolbar 는 예제 위 단추 줄이다. 그 밖의 코드는 문서에서 그대로 실행된다.

높이

그리드는 넣은 요소를 가득 채운다. 그 요소에 높이가 없으면 아무것도 보이지 않는다.

/* 고정 높이 */
#grid { height: 400px; }

/* 화면 남는 높이를 채우기 (flex) */
.page { display: flex; flex-direction: column; height: 100vh; }
.page #grid { flex: 1; min-height: 0; }
가로 스크롤이 그리드 밖으로 번질 때

flex · grid 틀 안에서는 컬럼 너비 합만큼 틀이 넓어질 수 있다. 그리드를 넣은 요소에 min-width: 0 을 주면 가로 스크롤이 그리드 안에만 생긴다.

자료 바꾸기, 없애기

grid.setRows(newRows)      // 조회 결과로 바꾼다. rowKey 가 같은 행의 선택은 유지된다
grid.setColumns(newCols)   // 컬럼 정의를 바꾼다
grid.refresh()             // 행 값을 밖에서 고친 뒤 다시 계산해 그린다
grid.destroy()             // 화면을 떠날 때. 이벤트와 요소를 모두 걷는다

Vue 에 붙이기

공식 Vue 컴포넌트는 따로 없다. 코어가 프레임워크를 모르므로 얇게 감싸면 된다. 화면마다 감싸지 말고, 프로젝트에 공통 컴포넌트 하나를 둔다.

<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { createGrid, type ColumnDef, type Grid, type Row } from 'horee-grid'
import 'horee-grid/dist/horee-grid.css'

const props = defineProps<{ columns: ColumnDef[]; rows: Row[]; rowKey?: string }>()
const el = ref<HTMLDivElement>()
let grid: Grid | undefined

onMounted(() => {
  grid = createGrid(el.value!, { columns: props.columns, rows: props.rows, rowKey: props.rowKey })
})
watch(() => props.rows, rows => grid?.setRows(rows))
watch(() => props.columns, cols => grid?.setColumns(cols))
onBeforeUnmount(() => grid?.destroy())

defineExpose({ grid: () => grid })
</script>

<template><div ref="el" style="height: 100%; min-width: 0" /></template>
반응형 프록시를 넘기지 않는다

rows 를 reactive · ref 안에 두면 그리드가 프록시 객체를 받아 느려진다. 큰 목록은 shallowRef 에 두거나 toRaw(rows) 를 넘긴다.

React 에 붙이기

import { useEffect, useRef } from 'react'
import { createGrid, type ColumnDef, type Grid, type Row } from 'horee-grid'
import 'horee-grid/dist/horee-grid.css'

export function HoreeGrid({ columns, rows, rowKey }: { columns: ColumnDef[]; rows: Row[]; rowKey?: string }) {
  const el = useRef<HTMLDivElement>(null)
  const grid = useRef<Grid>()

  useEffect(() => {
    grid.current = createGrid(el.current!, { columns, rows, rowKey })
    return () => grid.current?.destroy()
  }, [])                                              // 한 번만 만든다
  useEffect(() => grid.current?.setRows(rows), [rows])
  useEffect(() => grid.current?.setColumns(columns), [columns])

  return <div ref={el} style={{ height: '100%', minWidth: 0 }} />
}

이벤트 옵션(onCellChange 등)이 최신 상태를 읽어야 하면 useRef 에 콜백을 담아 넘긴다.

script 태그로 쓰기

번들러가 없는 페이지에서는 UMD 파일을 넣는다. 전역 이름은 HoreeGrid 다.

<link rel="stylesheet" href="/lib/horee-grid.css">
<script src="/lib/horee-grid.umd.cjs"></script>
<script>
  const grid = HoreeGrid.createGrid(document.getElementById('grid'), { columns, rows })
</script>

라이선스 키 넣기

앱이 시작할 때 한 번 넣는다. 이미 만든 그리드도 바로 다시 검사한다.

import { setLicenseKey } from 'horee-grid'

setLicenseKey(import.meta.env.VITE_HOREE_GRID_KEY)
  • localhost · 127.0.0.1 같은 개발 주소에서는 키가 없어도 된다.
  • 키가 없거나 맞지 않아도 그리드는 멈추지 않는다. 오른쪽 아래에 안내 띠가 뜨고 콘솔에 이유가 한 번 남는다.
  • 자세한 내용은 라이선스 키.

다음 단계

하려는 일볼 곳
숫자에 쉼표, 날짜 서식, 열 고정, 머리글 묶음컬럼
칸을 고치고 저장편집
엑셀에서 붙여 넣기, 엑셀 파일로 내려받기복사 · 붙여넣기 · 엑셀
수십만 건 목록서버 자료
옵션 · 메서드 전체API