AkiFilter
Akifilter is a schema-driven filter component that provides a powerful, declarative way to build filter interfaces.
It handles form state, persistence, visibility management, and applied filter chips automatically.
Installation
pnpm add @akinon/akifilterBasic Usage
import { Akifilter, filterField, type AkifilterSchema } from '@akinon/akifilter';
interface FilterValues {
name: string;
status: string;
createdAt: Date | null;
}
const filterSchema: AkifilterSchema<FilterValues> = [
filterField<FilterValues>()
.key('name')
.type('text')
.label('Name')
.placeholder('Search by name...')
.visible()
.build(),
filterField<FilterValues>()
.key('status')
.type('select')
.label('Status')
.placeholder('Select status')
.options([
{ label: 'Active', value: 'active' },
{ label: 'Inactive', value: 'inactive' },
{ label: 'Pending', value: 'pending' }
])
.visible()
.build(),
filterField<FilterValues>()
.key('createdAt')
.type('date')
.label('Created Date')
.placeholder('Select date')
.build()
];
export const ProductFilters = () => {
const handleValuesChange = (values: Partial<FilterValues>) => {
console.log('Filter values changed:', values);
// Fetch data with new filter values
};
return (
<Akifilter
filterSchema={filterSchema}
onValuesChange={handleValuesChange}
storageNamespace="products"
/>
);
};Props
filterSchema
AkifilterSchema<T>
Declarative description of the filter fields
storageNamespace
string
Optional namespace for local storage persistence
defaultValues
Partial<T>
Default values supplied by the host application
onValuesChange
(values: Partial<T>) => void
Callback on every value change with normalised payload
onVisibleFieldsChange
(keys: string[]) => void
Callback when visible field keys change
onClearAll
() => void
Callback when user clears all filters
onImportCsv
() => void
Callback for CSV import action
onImportXls
() => void
Callback for XLS/XLSX import action
enableImportCsv
boolean
Shows the CSV import button in toolbar
enableImportXls
boolean
Shows the XLS/XLSX import button in toolbar
Filter Field Builder
Use filterField() builder to create filter field definitions with a fluent API:
Field Types
Text Field
Number Field
Select Field
Date Field
Date with Time
Checkbox Field
Textarea Field
Custom Field
For advanced use cases, use custom fields with a render function:
Field Visibility
By default, if no fields have explicit visibility set, the first 8 fields in the schema are shown. Use .visible() to explicitly mark which fields should appear in the main filter form:
If at least one field has .visible() set, only those explicitly marked fields will be shown by default. Otherwise, the first 8 fields are displayed.
Conditional Field Configuration
Fields can be dynamically disabled or hidden based on other field values:
Section Fields
Group related filters into collapsible sections:
Persistence
Akifilter automatically persists filter values and visibility settings to localStorage:
Filter values are stored under
appliedFilters-{namespace}Visibility settings are stored under
shownFilters-{namespace}Values persist across page reloads
Applied Filters
Active filter values are displayed as removable chips above the filter form:
Click the
×on a chip to remove that filterUse "Clear All" to reset all filters to defaults
Values are formatted based on field type (dates use locale format, booleans show Yes/No)
Visibility Modal
Users can customize which filters appear in the main form:
Click the "Select Filters" button in the toolbar
Search and paginate through available filters
Toggle checkboxes to show/hide filters
Selections are persisted to localStorage
Import Actions
Enable CSV/XLS import buttons for bulk filter operations:
Complete Example
Internationalization
Akifilter uses @akinon/akilocale for built-in translations. Default labels and messages are provided in English and Turkish.
Best Practices
Define TypeScript interfaces - Always type your filter values for better type safety
Use meaningful storage namespaces - Prevents conflicts between different filter instances
Mark primary filters as visible - Show the most commonly used filters by default
Group related filters - Use section fields to organize complex filter sets
Handle empty states - Provide appropriate feedback when no filters are applied
Last updated
Was this helpful?

