Crossfilter in HTML: explain why a category group ignores its own filter

Explain selected counts and available region counts without mixing their filter contexts.

The selected-record count says two, while the category summary still lists records from another category. That can be intentional Crossfilter behavior. A dimension's group ignores the filter on that same dimension; the top-level groupAll() observes all current filters. Label those results according to the question each one answers.

Take four fictional packing records: North has quantities six and four; South has five and three. There are four records and eighteen units overall. Filtering to North leaves two records and ten units. Do not describe those two different measures as interchangeable totals.

Region counts: selected records versus available categories
Region counts: selected records versus available categories
Open the full example ↗

Open the complete example · Download the full HTML source

Keep the filter dimension and summary separate

The Crossfilter API reference documents dimensions, filters, groups, and the top-level all-record reduction. The maintained package is named crossfilter2. After loading its chosen browser distribution, the core model can be:

const data = crossfilter(records);
const byRegion = data.dimension(row => row.region);
const regions = byRegion.group().reduceCount();
const selectedCount = data.groupAll().reduceCount();
const selectedUnits = data.groupAll().reduceSum(row => row.units);

records must be supplied by your application. Use numbers for units before constructing the model. The category summary is not an HTML row count; it is a reduction with its own documented filter semantics.

Apply one region and read both answers

Call byRegion.filterExact('North'), then refresh the page's displayed results. selectedCount.value() should represent the records surviving all current filters. selectedUnits.value() should represent their summed units.

The regions group is associated with byRegion, so it ignores that dimension's own filter. In this supplied one-dimension model, it continues to describe both regions. A useful label is “Region counts before the region filter.” It is misleading to label it “Current selected records” and leave the reader to reconcile the apparent contradiction.

If another dimension is added later, that other dimension's filter affects this group. The label and explanation must then reflect the additional filtering context; “all original records” would no longer necessarily be correct.

Clear the filter without deleting source data

Use byRegion.filterAll() to remove the region restriction and refresh both reductions. For the supplied data, the selected count returns to four and selected units to eighteen. A South selection gives two and eight. Independently calculate six plus four and five plus three before judging the interface correct.

The existing table sorting and filtering guide hides DOM rows directly. Crossfilter maintains a data model and reductions. Keep that distinction clear when a chart, table, and selected total share a filter.

For a reading copy in NOS, put the filter label beside each count. Ask the reviewer whether a category summary should preserve the available alternatives or describe only the current selection. That choice determines which answer belongs on the page.

Keep reading