horee-gridb0.0.1

Styling

The default look is close to Excel. Change colors, fonts and sizes with CSS variables, and highlight rows and cells with classes. You will rarely need to override the grid's internal CSS.

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

const rows = Array.from({ length: 100 }, (_, i) => ({ id: i + 1, item: `Item ${i + 1}`, stock: (i * 37) % 120, safe: 40 }))

const grid = createGrid(host, {
  locale: 'en',
  rowKey: 'id',
  rowHeight: 32,
  columns: [
    { field: 'item', title: 'Item', flex: 1 },
    { field: 'stock', title: 'Stock', type: 'number', width: 100 },
    { field: 'safe', title: 'Safety stock', type: 'number', width: 100 }
  ],
  rows,
  rowClass: r => (r.stock < r.safe ? 'short' : undefined)
})

const css = document.createElement('style')
css.textContent = `
  .hg.theme-ocean { --hg-accent: #0b63ce; --hg-sel: #dbe9ff; --hg-head-bg: #eef3fa; --hg-line: #d5deea; }
  .hg.theme-ink { --hg-bg: #111418; --hg-fg: #e5e8eb; --hg-line: #2a2f36; --hg-head-bg: #191d22; --hg-head-fg: #aab2bb;
    --hg-sel: #273244; --hg-hover: #1a2029; --hg-accent: #f0b429; }
  .hg-row.short .hg-cell { color: #d1242f; }`
document.head.append(css)

toolbar.innerHTML = `
  <button data-theme="">Default</button><button data-theme="theme-ocean">ocean</button><button data-theme="theme-ink">ink</button>
  <button data-lines="all">lines all</button><button data-lines="row">lines row</button><button data-lines="none">lines none</button>`
toolbar.onclick = e => {
  const el = host.querySelector('.hg')
  const { theme, lines } = e.target.dataset
  if (theme !== undefined) {
    el.classList.remove('theme-ocean', 'theme-ink')
    if (theme) el.classList.add(theme)
  }
  if (lines) {
    // Same classes the lines option adds (usually you pass lines: 'row' when creating)
    el.classList.remove('hg-lines-row', 'hg-lines-none')
    if (lines !== 'all') el.classList.add('hg-lines-' + lines)
  }
}

CSS variables

Set them on the grid element (.hg) or any element above it. One set for the whole app, a different set per screen, or just one grid — all work the same way.

:root {
  --hg-font: "Inter", sans-serif;
  --hg-font-size: 13px;
  --hg-accent: #0b63ce;
}
.dark .hg {
  --hg-bg: #111418;
  --hg-fg: #e5e8eb;
  --hg-line: #2a2f36;
  --hg-head-bg: #191d22;
}
VariableUsed forDefault
--hg-fontFontInherited
--hg-font-sizeFont size13px
--hg-bgCell background#fff
--hg-fgText#1f2328
--hg-lineCell lines · borders#d4d4d4
--hg-head-bgHeader · row number background#f3f3f3
--hg-head-fgHeader text#333
--hg-foot-bgFixed bottom row (totals) background--hg-head-bg
--hg-selSelected row background#e2f0d9
--hg-hoverRow under the mouse#f5f9ff
--hg-accentActive cell · sort marker · checkbox · drag marker#107c41
--hg-dirtyChanged cell mark#e8590c
--hg-errorInvalid value border#d93025
--hg-row-hRow height (set by the rowHeight option)27px
Row height is an option

The grid sets --hg-row-h itself from the rowHeight option. It is used for scroll calculations, so do not change it in CSS; set rowHeight instead. The header row height is headerHeight (default row height + 2).

Cell lines

createGrid(host, { columns, rows, lines: 'row' })
linesLook
'all' (default)Horizontal and vertical lines, like Excel
'row'Horizontal lines only; suits read-only lists
'none'No lines

Highlighting rows and cells

createGrid(host, {
  columns,
  rows,
  rowClass: row => (row.stock < row.safe ? 'short' : undefined)
})
.hg-row.short .hg-cell { color: #d1242f; }
.hg-row.short .hg-cell:first-child { font-weight: 600; }

For a single cell, use the column's cellClass:

{ field: 'diff', title: 'Difference', type: 'number', cellClass: ({ value }) => (value ? 'warn' : undefined) }
Backgrounds go on cells

A background on .hg-row is not visible, because each cell (.hg-cell) has its own background. Use .hg-row.name .hg-cell.

Classes the grid adds

You can rely on these classes in your CSS. Other internal class names may change between versions.

ClassWhere
.hgThe grid's outer element
.hg-row · .hg-cellRows · cells
.hg-cell[data-c="column id"]Cells of a specific column
.hg-selSelected rows (.hg-row)
.hg-curCurrent row (setCurrent)
.hg-activeActive cell
.hg-dirtyChanged cell
.hg-footFixed bottom row area
.hg-loadingLoading server data (.hg)
.hg-lines-row · .hg-lines-noneThe lines option (.hg)

Dark mode

Just change the variables. The examples in these docs switch the same way when you click the ☾ button at the top right.

[data-theme="dark"] .hg {
  --hg-bg: #14181c;
  --hg-fg: #e6e9ec;
  --hg-line: #2a3037;
  --hg-head-bg: #1b2026;
  --hg-head-fg: #c3cad2;
  --hg-sel: #17352a;
  --hg-hover: #1a222a;
  --hg-accent: #3ccf7f;
}