horee-gridb0.0.1

Columns

Most of a grid's appearance is decided by its column definitions (ColumnDef). This page covers them in the order you will most often need them. For every property see API › ColumnDef.

columns.js
import { createGrid } from 'horee-grid'

const status = { 0: ['To do', '#8b929a'], 1: ['Doing', '#2f6fdb'], 2: ['Done', '#107c41'] }
const rows = Array.from({ length: 300 }, (_, i) => ({
  no: i + 1,
  title: `Task ${i + 1} — ${['Equipment check', 'Material receipt', 'Quality inspection', 'Shipping prep'][i % 4]}`,
  state: i % 3,
  plan: 100 + (i % 7) * 25,
  done: (i * 37) % 260,
  due: `2026-12-${String((i % 28) + 1).padStart(2, '0')}`
}))

const grid = createGrid(host, {
  locale: 'en',
  rowKey: 'no',
  columns: [
    { field: 'no', title: 'No.', width: 64, fixed: 'left', align: 'center' },
    { field: 'title', title: 'Task', flex: 1, minWidth: 200, tooltip: true },
    {
      field: 'state', title: 'Status', width: 80, align: 'center',
      // Draw the cell yourself: return an element or text
      render: ({ value }) => {
        const badge = document.createElement('span')
        badge.textContent = status[value][0]
        badge.style.cssText = `color:#fff;background:${status[value][1]};padding:1px 8px;border-radius:10px;font-size:11px`
        return badge
      }
    },
    {
      title: 'Quantity', headerTooltip: 'Actual vs. plan',
      children: [
        { field: 'plan', title: 'Plan', type: 'number', width: 80 },
        { field: 'done', title: 'Actual', type: 'number', width: 80 },
        {
          id: 'rate', title: 'Achieved', width: 90, align: 'right',
          value: r => r.done / r.plan,
          format: ({ value }) => (value * 100).toFixed(1) + '%',
          cellClass: ({ value }) => (value < 0.5 ? 'low' : undefined)
        }
      ]
    },
    { field: 'due', title: 'Due', type: 'date', width: 110, fixed: 'right' }
  ],
  rows
})

// The look of classes added by cellClass is up to your page CSS
const css = document.createElement('style')
css.textContent = '.hg-cell.low { color: #d1242f; font-weight: 600 }'
document.head.append(css)

Basics

{ field: 'name', title: 'Item', width: 160 }
PropertyMeaningDefault
fieldKey used to read the value from the row object—
idColumn identifier, used for sorting, filtering and saved statefield
titleHeader text—
widthWidth (px)120
align'left' · 'center' · 'right'left

A column without a field (a calculated column) must have an id. id must be unique within the grid.

Value types: number · date

A single type sets the format, sorting, editor and Excel cell format together.

{ field: 'amount', title: 'Amount', type: 'number' }              // 1,234,567 · right-aligned
{ field: 'rate', title: 'FX rate', type: 'number', decimals: 2 }  // 1,385.20
{ field: 'day', title: 'Posting date', type: 'date' }             // 2026-11-15 · centered
typeOn screenSort · filterExcel
text (default)Value as isText comparison (natural order for letters and numbers)Text
numberThousands separators, decimals placesNumeric comparisonNumber cell
dateOption dateFormat (default yyyy-mm-dd)Date comparisonDate cell
  • Date values may be Date, '20261115', '2026-11-15', '2026/11/15' or '2026.11.15'. A trailing time is fine.
  • Change the date look for the whole grid with an option such as dateFormat: 'yyyy.mm.dd'.
  • Number separators always use the 1,234.5 form regardless of locale.

Width

{ field: 'memo', title: 'Memo', flex: 1, minWidth: 200 }
  • Columns with flex share the leftover width in that ratio and follow the grid when its width changes.
  • If a user drags a flex column's width, it is fixed at that width.
  • To stop users resizing, set resizable: false on the column, or the option columnResize: false for the whole grid.

Fixed columns

{ field: 'code', title: 'Code', fixed: 'left' }
{ field: 'total', title: 'Total', fixed: 'right' }
  • They stay in place when scrolling horizontally. Both sides can hold several columns.
  • Setting fixed on a header group applies it to every column below.
  • When users drag columns, they can only move within the same area (left fixed · middle · right fixed).

Grouped headers

A column with children is a group. Groups can be nested, and the number of header rows follows the deepest group.

{
  title: 'Q1',
  children: [
    { title: 'Jan', children: [{ field: 'dr1', title: 'Debit' }, { field: 'cr1', title: 'Credit' }] },
    { title: 'Feb', children: [{ field: 'dr2', title: 'Debit' }, { field: 'cr2', title: 'Credit' }] }
  ]
}

In an Excel download, group headers become merged cells.

Calculated columns: value

Show a value that is not in the row. Sorting, filtering and Excel use this value too.

{ id: 'rate', title: 'Achieved', value: r => r.done / r.plan, format: ({ value }) => (value * 100).toFixed(1) + '%' }
Total rows and calculated columns

Fixed bottom rows (bottomRows) also go through the same value function. To put precomputed values in a total row, use field instead of value and store the computed value in the row object.

Displayed text: format

Keep the value and change only the text on screen. It receives a CellInfo (value, row, column, rowIndex, bottom).

{ field: 'kind', title: 'Type', format: ({ value }) => ({ P: 'Part', C: 'Consumable' })[value] ?? '' }
{ field: 'qty', title: 'Qty', type: 'number', format: ({ value, bottom }) => (bottom ? `Sum ${value}` : String(value)) }

format takes precedence over the default format of type. The grid filter's "contains" and "equals" pass if either the displayed text or the original value matches.

Custom drawing: render

Return an element or text and it is placed in the cell. null means default drawing.

{
  field: 'state', title: 'Status',
  render: ({ value }) => {
    const b = document.createElement('span')
    b.className = 'badge badge-' + value
    b.textContent = value
    return b
  }
}
Keep render light

It is called for visible cells on every scroll. Creating a few elements is fine, but do not query data or mount large components inside a cell.

Cell and row classes

{ field: 'amt', title: 'Amount', type: 'number', cellClass: ({ value }) => (value < 0 ? 'neg' : undefined) }
createGrid(host, { columns, rows, rowClass: row => (row.closed ? 'closed' : undefined) })
.hg-cell.neg { color: #d1242f; }
.hg-row.closed .hg-cell { color: #8b929a; background: #fafafa; }

Put background colors on cells (.hg-cell), not rows, because the cells have their own background.

Tooltips

{ field: 'memo', title: 'Memo', tooltip: true }                               // the displayed text
{ field: 'code', title: 'Code', tooltip: ({ row }) => row.fullName }          // custom text
{ field: 'tgt', title: 'Target', headerTooltip: 'Accounts included in the calculation' }  // header

Custom sort comparison

const order = { High: 0, Normal: 1, Low: 2 }
{ field: 'pri', title: 'Priority', compare: (a, b) => order[a] - order[b] }

Without a compare function, blank values go last in both ascending and descending order.

Blocking user actions

What to blockOne columnWhole grid
Sortingsortable: false—
Resizingresizable: falsecolumnResize: false
Reorderingmovable: falsecolumnMove: false
Hide and filter menus—contextMenu: false