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
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 },
];Quick start
Section titled “Quick start”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 },];Operator and state
Section titled “Operator and state”- Type ID:
FILTER_STATISTICAL_PRESETS('statisticalPresets') - Operator ID:
STATISTICAL_PRESET_OPERATOR('statisticalPreset') - Presets:
top10Percent,aboveAverage,bottomQuartile,outliersTwoSigma, andnegativeOnly - 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 a preset programmatically
Section titled “Restore a preset programmatically”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.
Configuration
Section titled “Configuration”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.
Common mistakes
Section titled “Common mistakes”- 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
negativeOnlyas “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.