Lattice Grid Buy a licence

demo D34

Progress and bullet in htmx

Completion against a target, with a threshold marker

render: 'progress' | 'bullet'

This grid draws completion against a target as a filled bar and a bullet gauge with a threshold marker. It makes a single number readable next to its ceiling, so storage used, quota consumed or work done reads at a glance rather than as a bare figure.

Building…
Loading a live grid…

This is the htmx version. A server-rendered table is upgraded in place, so the page is readable before any script runs and gains the full grid when the module loads, which suits a progressively enhanced app.

The configuration

<link rel="stylesheet" href="https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.min.css">

<!-- A real, server-rendered table: readable with JavaScript off. data-field on
     each header names the column that cell becomes, and data-id on each row is
     the key the grid carries it under. -->
<table id="progress-and-bullet-table" data-lattice-grid>
  <thead>
    <tr>
      <th data-field="service">Service</th>
      <th data-field="team">Team</th>
      <th data-field="completion">Migration</th>
      <th data-field="utilisation">Capacity</th>
      <th data-field="attainment">Against plan</th>
      <th data-field="target">Target</th>
      <th data-field="cost">Monthly cost</th>
    </tr>
  </thead>
  <tbody>
    <tr data-id="0"><td>fraud-edge</td><td>Commerce</td><td>95</td><td>27</td><td>67</td><td>64</td><td>2863.61</td></tr>
    <tr data-id="1"><td>payments-stream</td><td>Growth</td><td>43</td><td>74</td><td>100</td><td>79</td><td>4874.98</td></tr>
    <tr data-id="2"><td>checkout-edge</td><td>Payments</td><td>3</td><td>54</td><td>96</td><td>56</td><td>3552.72</td></tr>
    <!-- the rest of the rows, rendered by your server -->
  </tbody>
</table>

<script type="module">
  import { hydrateTable } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/htmx.esm.min.js';

  // The markup carries the rows; a server-rendered table's column types are
  // declared in the config hydrateTable takes. The grid replaces the table
  // where it stood.
  const grid = hydrateTable(document.getElementById('progress-and-bullet-table'), {
    selection: 'multiple',
    toolPanel: {
      side: 'left',
      panels: ['columns', 'filters', 'views', 'quick'],
      actions: ['undo', 'redo', 'export', 'restore', 'maximise'],
      exportName: 'lattice-demo',
    },
    columns: [
      { field: 'service', title: 'Service', layout: { pin: 'start', width: 170 } },
      { field: 'team', title: 'Team', filter: { type: 'set' } },
      // progress draws a value as a length.
      { field: 'completion', title: 'Migration', type: 'number', layout: { width: 220 },
        format: { suffix: '%' }, cell: { render: 'progress' } },
      // variant selects a theme token rather than a colour of its own.
      { field: 'utilisation', title: 'Capacity', type: 'number', layout: { width: 220 },
        format: { suffix: '%' }, cell: { render: 'progress', props: { variant: 'warning' } } },
      // bullet adds an opinion about what good looks like: bands shade the track
      // and the tick marks the target.
      { field: 'attainment', title: 'Against plan', type: 'number', layout: { width: 240 },
        format: { suffix: '%' }, cell: { render: 'bullet', props: { min: 0, max: 120, bands: [60, 90], target: 85 } } },
      { field: 'target', title: 'Target', type: 'number', layout: { width: 110 }, format: { suffix: '%' } },
      { field: 'cost', title: 'Monthly cost', type: 'number', layout: { width: 150 },
        format: { style: 'currency', currency: 'USD' }, total: 'sum' },
    ],
  });
</script>

Showing completion against a target with progress and bullet renderers

A progress renderer draws a filled bar against a maximum, the shape behind storage usage, project completion and quota consumption, anything where a single number only makes sense next to its ceiling. A bullet renderer covers the case one step up: a value plotted against a target with a threshold marker crossing it, the pattern KPI dashboards use to show a metric against a goal rather than an empty range. A developer reaches for either when a bare number in a cell would force a reader to do the comparison in their head. Lattice Grid selects between them with render: 'progress' | 'bullet' on the column definition, and the bullet variant takes the extra threshold value as a second field so the marker moves independently of the bar. Both are drawn with CSS widths and a couple of absolutely positioned spans rather than SVG or canvas, so a column of bars in a JavaScript data grid repaints on scroll and resize at the same cost as any other cell content, with no separate chart library loaded for what is, visually, two rectangles and a line. Colour and threshold are read per row, so a bar can flip from a pass colour to a warning colour the moment its row crosses the marker, without a second pass over the data.

How do you show a value against a target in a data grid column?

Set render: 'bullet' on the column and supply both the value field and a threshold field; Lattice Grid draws the value as a bar and the threshold as a marker line crossing it, so a reader compares the two at a glance. Use render: 'progress' instead when there is a maximum but no separate threshold to mark, such as storage used out of a quota.