Grid
An HTML data grid that runs spreadsheet formulas in the page
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
- Plain JavaScript modules with no framework, so the grid can sit in any page.
- 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).
- An existing open-source formula parser does the maths, so common spreadsheet functions work without writing my own.
- 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.
- 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
- A formula bar shows the selected cell's address and its raw value or formula.
- Editing a quantity or price updates the line total, the subtotal and the final total straight away.
- Clicking into a formula outlines the cells it uses, including whole ranges like D2:D4.
- Drag to select a range; hold Ctrl to add more ranges, each in its own colour.
- A familiar toolbar and sheet tabs along the bottom.
Built with JavaScript (ES modules), HTML, CSS, fast-formula-parser, 2024.