Skip to content

Statistical Presets Filter

Statistical presets turn common analytical questions into one-click filters. Use them for metrics where users frequently ask for the top 10%, values above average, the bottom quartile, two-sigma outliers, or negative values.

Source code
TypeScriptts
grid.plugins = [AdvanceFilterPlugin];
grid.columns = [
  {
    prop: 'margin',
    name: 'Margin',
    filter: ['number', FILTER_STATISTICAL_PRESETS],
  },
];
grid.filter = true;

return [
  { margin: -12 },
  { margin: -3 },
  { margin: 0 },
  { margin: 4 },
  { margin: 7 },
  { margin: 11 },
  { margin: 18 },
  { margin: 25 },
  { margin: 40 },
  { margin: 95 },
];
import { defineCustomElements } from '@revolist/revogrid/loader';
import {
AdvanceFilterPlugin,
FILTER_STATISTICAL_PRESETS,
} from '@revolist/revogrid-pro';
import '@revolist/revogrid-pro/dist/revogrid-pro.css';
defineCustomElements();
const grid = document.createElement('revo-grid');
grid.plugins = [AdvanceFilterPlugin];
grid.columns = [
{ prop: 'team', name: 'Team' },
{
prop: 'margin',
name: 'Margin',
filter: ['number', FILTER_STATISTICAL_PRESETS],
},
];
grid.filter = true;
document.querySelector('#app')!.append(grid);
grid.source = [
{ team: 'North', margin: 18 },
{ team: 'South', margin: -4 },
{ team: 'West', margin: 31 },
{ team: 'East', margin: 9 },
];
  • Type ID: FILTER_STATISTICAL_PRESETS ('statisticalPresets')
  • Operator ID: STATISTICAL_PRESET_OPERATOR ('statisticalPreset')
  • Presets: top10Percent, aboveAverage, bottomQuartile, outliersTwoSigma, and negativeOnly
  • Value: { preset, lower, upper, lowerInclusive, upperInclusive, outside }

The popup computes statistics from the current finite parsed values. When a preset is selected, the resolved numeric boundaries are serialized into the condition. Those boundaries stay stable when the source later changes; reopen and select the preset again to recompute it.

Restore the resolved boundaries, not only the preset name:

import {
STATISTICAL_PRESET_OPERATOR,
defineAdvancedFilterConfig,
} from '@revolist/revogrid-pro';
grid.filter = defineAdvancedFilterConfig({
multiFilterItems: {
margin: [
{
id: 1,
type: STATISTICAL_PRESET_OPERATOR,
value: {
preset: 'negativeOnly',
lower: null,
upper: 0,
lowerInclusive: false,
upperInclusive: false,
outside: false,
},
relation: 'and',
},
],
},
});

null represents an unbounded side. outside: true matches values outside the serialized lower and upper boundaries and is used by the two-sigma outlier preset.

import {
createStatisticalPresetsStructuredFilterType,
defineAdvancedFilterConfig,
} from '@revolist/revogrid-pro';
const presets = createStatisticalPresetsStructuredFilterType({
formatValue: (value) => `${value.toFixed(1)}%`,
formatMatchCount: (count) => `${count.toLocaleString()} matches`,
});
grid.filter = defineAdvancedFilterConfig({
structuredFilterTypes: [presets],
});

Both callbacks change presentation only. Use cellParser when the stored value must be normalized before statistics and comparisons are calculated.

  • Saving only { preset: 'top10Percent' }; all boundary and inclusion fields are required for a valid restored condition.
  • Expecting an applied preset to move automatically as rows change; its serialized boundaries are deliberately stable.
  • Including NaN, Infinity, or nonnumeric strings in expected statistics; only finite parsed values participate.
  • Treating negativeOnly as “zero or below”; its upper boundary is exclusive, so zero does not match.
  • Recomputing boundaries independently with different quantile or variance rules when the application can save the condition emitted by the grid.