Lattice Grid Buy a licence

demo D173

Brushing a time range in Svelte

Drag a range on the chart and the grid narrows to it

brush: true

This lets you drag a range across a time chart and narrows the grid to it. It gives a reader a quick way to focus on a period, selecting the window on the chart and reading the matching rows in the grid.

Building…
Loading a live grid…

This is the Svelte version. A use action attaches the grid to a plain element, so no framework runtime is passed in and the component stays small, while the configuration is ordinary Svelte state.

The configuration

<script>
  import { createGrid } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/lattice-grid.esm.min.js';
  import createLatticeAction from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/svelte.esm.min.js';
  import { createChart } from 'https://cdn.latticegrid.dev/lattice-grid@1.107.0/modules/charts.esm.min.js';

  const lattice = createLatticeAction({ createGrid });

  let chartEl;

  const config = {
    rowKey: 'id',
    columns: [
      { field: 'date', title: 'Date', type: 'dateString' },
      { field: 'price', title: 'Price', type: 'number', format: { decimals: 2 } },
      { field: 'volume', title: 'Volume', type: 'number', format: { notation: 'compact' } },
    ],
    rows,  // one row a day: date, price, volume
    // onGrid hands over the live grid the moment it is created. brush lets you
    // drag a range on the chart to narrow the grid to it, and the chart follows
    // the grid's filters and sort from then on.
    onGrid: (grid) => {
      createChart({ grid, container: chartEl, type: 'line', x: 'date', y: 'price', brush: true,
        title: 'Price over time (brush to filter)' });
    },
  };
</script>

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

<div bind:this={chartEl} style="height: 300px"></div>
<div use:lattice={config} style="height: 340px; margin-top: 14px"></div>