Faceted filters
A set filter lists each distinct value with a live count and narrows as you pick — and the
facets are faceted: selecting a value in one column re-narrows the counts in the others, but a
column never narrows its own list. In client mode the counts are derived from the loaded rows; in
server / infinite mode the engine supplies them via facet_counts (keyed into column_facets),
because the browser only holds a window and can’t count the whole frame. Either way the frontend
does zero math over them.
This one is best seen in a running app. The code below wires it in each framework.
from dash_tensor_grid import GridDataEngine, TensorGrid
engine = GridDataEngine(df) # a large flat frameFACET_COLS = ["region", "status", "amount"]
def facets(filters): # Each column self-excluded (faceted search); recompute only when the filter model changes. return {c: engine.facet_counts(c, filters=filters) for c in FACET_COLS}
grid = TensorGrid( id="grid", column_defs=[ {"accessorKey": "region", "header": "Region", "type": "string", "filterType": "set"}, {"accessorKey": "status", "header": "Status", "type": "string", "filterType": "select"}, {"accessorKey": "amount", "header": "Amount", "type": "number", "filterType": "range"}, ], column_facets=facets({}), # seed the initial (unfiltered) facets row_model="infinite", row_count=len(df),)
# In the rows_request callback, return refreshed column_facets when `filters` changes.import { TensorGrid } from '@tensorgrid/react';
// `rootFilter="set"` derives the value list + counts client-side (core facetCounts).<TensorGrid data={data} rows={['region', 'country']} measures={{ revenue: 'sum' }} enableColumnFilters rootFilter="set"/>;<TensorGrid :data="data" :rows="['region', 'country']" :measures="{ revenue: 'sum' }" enable-column-filters root-filter="set"/>import { facetCounts } from '@tensorgrid/core';
// The set-filter value list + counts for a column, faceted by the other active filters.const region = facetCounts(data, 'region', { kind: 'set' });// -> { type: 'set', column: 'region', values: [{ value: 'EMEA', count: 4 }, …], total, truncated }
// Render your own checkbox list from `region.values`, then drive the grid with setFilter.- Faceted search. The facet for a column reflects every other active filter but not its own, so picking a value narrows the sibling columns while the column keeps every value still reachable.
facet_counts/facetCountsreturn either asetresult (values: [{value, count}],total,truncated) or arangeresult ({min, max, count}); asetlist is capped (top ~200) withtruncatedflagging that more distinct values exist.- Server mode. Feed
column_facetsfrom the engine whenrow_model="infinite"— recompute only when the filter model changes, not on scroll. See filtering for the control types and infinite row model for the windowed data path.