import { FilterActionOnDataChange } from '../AdaptableState/Common/FilterActionOnDataChange'; import { BaseContext } from '../../types'; import { AdaptableColumn } from '../AdaptableState/Common/AdaptableColumn'; import { SystemAlertPredicateId, SystemFilterPredicateId } from '../../types'; import { StrictExtract } from '../Utilities/Extensions/TypeExtensions'; import { AdaptableColumnContext } from '../AdaptableState/Common/AdaptableColumnContext'; import { IRowNode } from 'ag-grid-enterprise'; /** * Options for managing Column & Grid Filters in AdapTable */ export interface FilterOptions { /** * Options for managing Column Filters */ columnFilterOptions?: ColumnFilterOptions; /** * Options for managing the Grid Filter */ gridFilterOptions?: GridFilterOptions; /** * Clear Grid and Column Filters when AdapTable loads * * @defaultValue true * @gridInfoItem * @noCodeItem */ clearFiltersOnStartUp?: boolean; /** * Provide custom values (or sorting / count info) when using `In` Predicate in Column or Grid Filter * @param context * @returns */ customInFilterValues?: (context: CustomInFilterValuesContext) => Promise | InFilterValueResult; /** * When to re-filter grid after data changes: 'Always', 'Never' or 'Throttle' (with a delay value) * * @defaultValue 'Always' */ filterActionOnDataChange?: FilterActionOnDataChange; /** * Allow filtering on Calculated & FreeText columns * * @defaultValue true * @gridInfoItem */ enableFilterOnSpecialColumns?: boolean; /** * Configures whether Rows will be evaluated when filtering * * @param context * @returns boolean */ isRowFilterable?: (context: IsRowFilterableContext) => boolean; /** * Show Date Picker (or Date Input) in Filter controls * @gridInfoItem * @noCodeItem * @defaultValue true */ showDatePicker?: boolean; /** * Use Adaptable's Column & Grid Filters in preference to AG Grid's filtering * * @defaultValue true * @noCodeItem */ useAdaptableFiltering?: boolean; } /** * Options for managing Column Filtering in AdapTable */ export interface ColumnFilterOptions { /** * Make Column Header distinctive for filtered columns, helps users see currently filtered columns * * @defaultValue true * @gridInfoItem * @noCodeItem */ indicateFilteredColumns?: boolean; /** * Manually apply Column Filters; an Apply Filter button is displayed and Quick Filter is disabled * * @defaultValue false * @gridInfoItem * @noCodeItem */ manuallyApplyColumnFilter?: boolean | ((context: AdaptableColumnContext) => boolean); /** * Default filter type for numeric Columns * * @defaultValue Equals * @gridInfoItem */ defaultNumericColumnFilter?: StrictExtract | ((adaptableColumnContext: DefaultPredicateFilterContext) => StrictExtract); /** * Default filter type for text Columns * * @defaultValue Contains * @gridInfoItem */ defaultTextColumnFilter?: StrictExtract | ((adaptableColumnContext: DefaultPredicateFilterContext) => StrictExtract); /** * Default filter type for date Columns * * @defaultValue On * @gridInfoItem */ defaultDateColumnFilter?: StrictExtract | ((adaptableColumnContext: DefaultPredicateFilterContext) => StrictExtract); /** * Default filter type for array Columns ('textArray', 'numberArray', etc.) * * @defaultValue In * @gridInfoItem */ defaultArrayColumnFilter?: StrictExtract | ((adaptableColumnContext: DefaultPredicateFilterContext) => StrictExtract); /** * Hides Dropdown in Quick Filter Bar for a given Column * * @defaultValue undefined */ hideQuickFilterDropdown?: (adaptableColumnContext: AdaptableColumnContext) => boolean; /** * Hides Input in Quick Filter Bar for a given Column * * @defaultValue undefined */ hideQuickFilterInput?: (adaptableColumnContext: AdaptableColumnContext) => boolean; /** * Height of Quick Filter Bar (if not provided, AG Grid default is used) * * @defaultValue null * @gridInfoItem */ quickFilterHeight?: number; /** * Display Quick Filter Bar between Column Header and Grid (provided its been setup) * @defaultValue true * @noCodeItem */ showQuickFilter?: boolean; /** * Shortcut Keys to activate a Quick Filter Predicate */ quickFilterWildcards?: Partial>; /** * Time to wait (in ms) before Filter Bar reacts to new value * @defaultValue 250 * @gridInfoItem */ quickFilterDebounce?: number; } /** * Options for managing the Grid Filter in AdapTable */ export interface GridFilterOptions { /** * Which UI Components can be used to edit a Grid Filter: Expression Editor, Query Builder (or both) * * @defaultValue ['ExpressionEditor', 'QueryBuilder'] */ availableFilterEditors?: GridFilterEditors; } /** * Context used for setting whether a Row can be Column Filtered */ export interface IsRowFilterableContext extends BaseContext { /** * The Row Node about to be evaluated */ rowNode: IRowNode; /** * The data in the Row Node */ data: TData; } /** * AdapTable's Filter components: FilterBar or FilterForm */ export type AdaptableFilterComponentLocation = 'FilterBar' | 'FilterForm'; /** * Context used for setting default Predicates for Column Filters */ export interface DefaultPredicateFilterContext extends BaseContext { /** * Filter Component being displayed: FilterBar or FilterForm */ filterComponent: AdaptableFilterComponentLocation; /** * Current Column */ column: AdaptableColumn; } /** * Item in the IN Column Filter */ export interface InFilterValue { /** * Item's label */ label: string; /** * The value of Item being shown */ value: ValueType; /** * Tooltip for Item (if true, the label is used as tooltip) */ tooltip?: boolean | string; level?: number; children?: InFilterValue[]; } /** * Result when providing custom values for the IN Column Filter */ export interface InFilterValueResult { /** * List of Items to display in the IN Column Filter */ values: InFilterValue[]; /** * If true, AdapTable will not filter the list using the current search value */ skipDefaultSearch?: boolean; } /** * Information about items in the IN Column Filter */ export interface InFilterValueInfo extends InFilterValue { /** * Whether Item is currently selected */ isSelected?: boolean; /** * How many times Item appears in the column */ count?: number; /** * How many times Item appears in the column in filtered rows */ visibleCount?: number; /** * Whether Item is currently visible in Grid (i.e. in filtered rows) */ visible?: boolean; children?: InFilterValueInfo[]; /** * For the grouping scenario, how many leafs are there under this item */ leafChildrenCount?: number; } /** * Context used when providing values for the IN Column Filter */ export interface CustomInFilterValuesContext extends AdaptableColumnContext { /** * Distinct Column values in natural (unsorted) row iteration order. * * When the Column uses a Tree Filter, items have a hierarchical structure. * * Computed lazily on first access. */ defaultValues: Required[]; /** * Distinct Column values sorted by the Column's own sort direction (Asc / Desc). * * If the Column has no active sort, values are returned in the same order as `defaultValues`. * * When the Column uses a Tree Filter, items have a hierarchical structure. * * Computed lazily on first access. */ sortedValues: Required[]; /** * Distinct Column values in the order they appear in the grid from top to bottom. * * Always a flat list, even when the Column uses a Tree Filter. * * Computed lazily on first access. */ orderedValues: Required[]; /** * Current text in the IN Filter search box. * * Useful when implementing server-side filtering of the value list. */ currentSearchValue: string; /** * The result returned by the previous invocation of `FilterOptions.customInFilterValues`, if any. * * Useful for avoiding expensive recomputations (e.g. when filtering is async or server-side). */ previousFilterResult?: InFilterValueResult; } /** * List of Editors that can be used when creating the Grid Filter */ export type GridFilterEditors = GridFilterEditor[]; /** * Editor to use for Grid Filter: 'ExpressionEditor' or 'QueryBuilder' */ export type GridFilterEditor = 'ExpressionEditor' | 'QueryBuilder';