Skip to content

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 frame
FACET_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.
  • 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 / facetCounts return either a set result (values: [{value, count}], total, truncated) or a range result ({min, max, count}); a set list is capped (top ~200) with truncated flagging that more distinct values exist.
  • Server mode. Feed column_facets from the engine when row_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.