All work

Grid

An HTML data grid that runs spreadsheet formulas in the page

Grid editor with the subtotal cell selected; its formula =SUM(D2:D4) is in the formula bar and the range D2 to D4 is outlined with a dashed orange border.

The problem

Websites that show prices, quotes or invoices usually show a static table. If a visitor wants to try a different quantity or price, they copy the numbers into a spreadsheet and work it out there.

I wanted a grid you can drop into a web page that understands spreadsheet formulas, so the page itself can do the sums: change one cell and the totals follow.

What I built

  1. Plain JavaScript modules with no framework, so the grid can sit in any page.
  2. The sheet is described as data: each cell has a position and a raw value, which is either a plain value or a formula like =B2*C2 or =SUM(D2:D4).
  3. An existing open-source formula parser does the maths, so common spreadsheet functions work without writing my own.
  4. When a cell changes, every cell whose formula refers to it is recalculated, and that change flows on to the cells that refer to those.
  5. Selections are drawn as coloured outlines over the table, and the cells a formula refers to are outlined with dashed lines in their own colour.

What it does

Built with JavaScript (ES modules), HTML, CSS, fast-formula-parser, 2024.