demo D171
Click a chart to filter
Click a slice and the grid narrows to it
chart.on('click', …)
Loading a live grid…
The configuration
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/lattice-grid.min.css">
<script type="module">
import { defineLatticeGrid } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/webcomponent.esm.js';
defineLatticeGrid();
</script>
<div id="chart" style="height: 260px"></div>
<lattice-grid row-key="id" style="display: block; height: 320px; margin-top: 14px"></lattice-grid>
<script type="module">
import { createChart } from 'https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.27.0/modules/charts.esm.min.js';
const el = document.querySelector('lattice-grid');
el.config = {
toolPanel: { side: 'left', panels: ['filters', 'columns'], exportName: 'circuits' },
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' },
],
};
el.rows = rows; // an array of circuit records
// el.grid is the live grid inside the element. Click a slice to narrow the
// grid to it; click the same slice again to clear.
const grid = el.grid;
const chart = createChart({ grid, container: '#chart', type: 'pie', x: 'status', y: 'charge' });
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;
}
});
</script>