Lattice Grid Buy a licence

demo D171

Click a chart to filter in Angular

Click a slice and the grid narrows to it

chart.on('click', …)

This lets you click a slice or bar in a chart and narrows the grid to it. It turns a chart into a filter control, so a reader drills from the picture into the exact rows behind it with one click.

Building…
Loading a live grid…

This is the Angular version. A standalone component takes the whole configuration through one config input, surfaces grid events as outputs, and exposes the live grid on a getter for anything the inputs do not cover.

The configuration

import { Component, ViewChild } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import { LatticeGridComponent, provideLattice } from '@toclocoinc/lattice-grid/angular';

const columns = [
  { field: 'circuit', title: 'Circuit', layout: { width: 180 } },
  { field: 'region', title: 'Region', filter: { type: 'set' } },
  { field: 'status', title: 'Status', filter: { type: 'set' } },
  { field: 'bandwidth', title: 'Bandwidth', type: 'number' },
  { field: 'charge', title: 'Monthly charge', type: 'number',
    format: { style: 'currency', currency: 'GBP' }, total: 'sum' },
];

const rows = [/* circuit records */];



@Component({
  selector: 'app-root',
  standalone: true,
  imports: [LatticeGridComponent],
  template:
    '<div id="chart" style="height:260px"></div>' +
    '<lattice-grid [config]="grid" (grid-ready)="onGridReady()" style="display:block;height:320px;margin-top:14px"></lattice-grid>',
})
export class AppComponent {
  @ViewChild(LatticeGridComponent) gridRef!: LatticeGridComponent;

  grid = {
    rowKey: 'id',
    toolPanel: { side: 'left', panels: ['filters', 'columns'], exportName: 'circuits' },
    columns: columns,
    rows: rows,
  };

  // The grid is created once the view has rendered, so the live instance
  // arrives on grid-ready rather than in ngAfterViewInit.
  onGridReady() {
    const grid = this.gridRef.grid;
    const chart = createChart({ grid, container: '#chart', type: 'pie', x: 'status', y: 'charge',
      title: 'Charge by status (click to filter)' });

    // Click a slice to filter the grid to it; click the same slice again to
    // clear. The chart reads the grid, so the bars redraw as the filter lands.
    let active = null;
    chart.on('click', ({ category }) => {
      const value = category;
      if (value == null) return;
      if (active === value) {
        grid.filters?.clear?.();
        active = null;
      } else {
        grid.filters?.set?.({ col: 'status', op: 'eq', value });
        active = value;
      }
    });
  }
}

bootstrapApplication(AppComponent, {
  providers: [provideLattice({ createGrid })],
});