はじめる
インストールから最初のグリッドを表示するまで 5 分ほどです。このページに沿って進め、残りのガイドは必要なときに参照してください。
インストール
horee-grid は npm の公開レジストリには公開していません。購入時に受け取るパッケージファイル(horee-grid-バージョン.tgz)をプロジェクト内に置いてインストールします。
# 受け取ったファイルをプロジェクトの vendor フォルダーに置いてから
npm install ./vendor/horee-grid-0.0.1-beta.1.tgzpackage.json には次のように残ります。バージョンを上げるときはファイルを差し替えて同じコマンドをもう一度実行します。
"dependencies": {
"horee-grid": "file:vendor/horee-grid-0.0.1-beta.1.tgz"
}バージョン番号が同じだと npm install だけでは新しいファイルに置き換わりません。上の npm install ./vendor/…tgz を直接実行してください。
パッケージの内容:
| ファイル | 内容 |
|---|---|
dist/horee-grid.js | ES モジュール(Vite · webpack などのバンドラー向け) |
dist/horee-grid.umd.cjs | UMD(<script> で読み込む、または CommonJS) |
dist/horee-grid.css | 標準のスタイル |
dist/types/*.d.ts | TypeScript の型定義 |
最初のグリッド
必要なのは 3 つだけです。高さのある要素、列定義、行の配列。
<div id="grid" style="height: 400px"></div>import { createGrid } from 'horee-grid'
const grid = createGrid(host, {
locale: 'ja',
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', locale: 'ja' })createGrid(要素, オプション)はGridオブジェクトを返します。以降はこのオブジェクトのメソッドで操作します(grid.setRows(…)、grid.getSelectedRows()…)。- 行はただのオブジェクトです。列の
fieldがオブジェクトのキーです。 rowKeyは行を識別するフィールドです。再照会で行を差し替えても選択とアクティブセルを保ち、select(キー)で行を選ぶときに使います。必ず指定することをおすすめします。- グリッドのメニューを日本語で表示するには
locale: 'ja'を指定します。言語・文言の変更 を参照してください。
サンプルコードの 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 コンポーネントはありません。コアはフレームワークに依存しないので、薄く包めば十分です。画面ごとに包まず、プロジェクトに共通コンポーネントを 1 つ置きます。
<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, locale: 'ja' })
})
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, locale: 'ja' })
return () => grid.current?.destroy()
}, []) // 1 回だけ作る
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, locale: 'ja' })
</script>ライセンスキーの設定
アプリの起動時に 1 回 設定します。すでに作ったグリッドもすぐに再検証されます。
import { setLicenseKey } from 'horee-grid'
setLicenseKey(import.meta.env.VITE_HOREE_GRID_KEY)localhost·127.0.0.1などの開発用アドレスではキーは不要です。- キーがなくても、合わなくても、グリッドは 止まりません。 右下に案内の帯が表示され、コンソールに理由が 1 回記録されます。
- 詳しくは ライセンスキー を参照してください。
次のステップ
| やりたいこと | 参照先 |
|---|---|
| 数値の桁区切り、日付の書式、列の固定、見出しのグループ化 | 列 |
| セルを編集して保存 | 編集 |
| Excel からの貼り付け、Excel ファイルでのダウンロード | コピー · 貼り付け · Excel |
| 数十万件の一覧 | サーバーデータ |
| オプション・メソッドの全体 | API |