Skip to content

Commit 9bd1cb5

Browse files
docs: document column filters
1 parent 5f1cb84 commit 9bd1cb5

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ https://www.nuget.org/packages/SoPro.FancyTable
3333
- Hideable columns via `Hideable`
3434
- Hidden-column restore buttons below the table
3535

36+
### Column filters
37+
- Opt-in per column via `Filterable`; a funnel icon in the header opens a popup with an operator and a value
38+
- Eight case-insensitive text operators: `Equals`, `NotEquals`, `Contains`, `NotContains`, `StartsWith`, `EndsWith`, `IsEmpty`, `IsNotEmpty`
39+
- Filters combine with AND across columns and with the active search
40+
- Filtered text comes from `SearchTextSelector`, falling back to `ValueSelector`
41+
- Host-owned persistence through `InitialColumnFilters` and `ColumnFiltersChanged`
42+
3643
### Column layout
3744
- Opt-in resizing and reordering for flat and tree tables
3845
- Content-based natural widths with optional `Width`, `MinWidth`, and `MaxWidth`
@@ -106,6 +113,8 @@ https://www.nuget.org/packages/SoPro.FancyTable
106113
| `EnableColumnReordering` | `bool` | Enables reorder handles; disabled by default |
107114
| `InitialColumnLayout` | `IReadOnlyList<FancyColumnLayout>?` | Initial order and optional widths, applied once per component instance |
108115
| `ColumnLayoutChanged` | `EventCallback<IReadOnlyList<FancyColumnLayout>>` | Raised with the complete normalized layout after a resize or reorder |
116+
| `InitialColumnFilters` | `IReadOnlyList<FancyColumnFilter>?` | Initial column filters, applied once per component instance; entries for unknown or non-`Filterable` columns are ignored |
117+
| `ColumnFiltersChanged` | `EventCallback<IReadOnlyList<FancyColumnFilter>>` | Raised with the complete list of active filters after a filter is applied or cleared |
109118

110119
## Tree Table Parameters
111120

@@ -200,6 +209,8 @@ private static readonly FancyTableTexts GermanTexts = FancyTableTexts.Default wi
200209
};
201210
```
202211

212+
The column filter popup adds these keys (English defaults): `FilterColumnFormat` ("Filter column {0}"), `FilterValuePlaceholder`, `ApplyFilterLabel`, `ClearFilterLabel`, and one label per operator: `FilterOperatorEqualsLabel`, `FilterOperatorNotEqualsLabel`, `FilterOperatorContainsLabel`, `FilterOperatorNotContainsLabel`, `FilterOperatorStartsWithLabel`, `FilterOperatorEndsWithLabel`, `FilterOperatorIsEmptyLabel`, `FilterOperatorIsNotEmptyLabel`.
213+
203214
The package also includes `FancyTable.resx`, `FancyTable.en.resx`, and `FancyTable.de.resx` so the same string catalog is already available for a future resource-driven integration layer.
204215

205216
## Column Configuration
@@ -213,6 +224,7 @@ Each column is configured using `FancyColumn<TItem>`:
213224
| `Sortable` | `bool` | Whether the column can be sorted |
214225
| `Searchable` | `bool` | Whether the column is included in search (default: `true`) |
215226
| `Hideable` | `bool` | Whether the column can be hidden by the user |
227+
| `Filterable` | `bool` | Whether the header shows a filter popup for this column (default: `false`) |
216228
| `Resizable` | `bool` | Whether the column can be resized when resizing is enabled (default: `true`) |
217229
| `Reorderable` | `bool` | Whether the column can be reordered when reordering is enabled (default: `true`) |
218230
| `Width` | `double?` | Initial width in pixels; natural content width is used when omitted |
@@ -248,6 +260,36 @@ Columns without `Width` or `MaxWidth` initially follow the currently rendered co
248260

249261
The first declared column of `FancyTreeTable` remains visible and fixed at the left while reordering is enabled. Non-reorderable columns act as boundaries that other columns cannot cross. Hidden columns retain their saved position and width.
250262

263+
### Column filters
264+
265+
Mark columns with `Filterable = true`. The host persists the filters; the component stores nothing itself. This example uses `localStorage` through `JSRuntime`:
266+
267+
```razor
268+
@inject IJSRuntime JS
269+
@using System.Text.Json
270+
271+
<FancyTable TItem="PersonRow"
272+
Items="People"
273+
Columns="PeopleColumns"
274+
InitialColumnFilters="SavedFilters"
275+
ColumnFiltersChanged="SaveFiltersAsync" />
276+
277+
@code {
278+
private IReadOnlyList<FancyColumnFilter>? SavedFilters;
279+
280+
protected override async Task OnInitializedAsync()
281+
{
282+
string? json = await JS.InvokeAsync<string?>("localStorage.getItem", "people-filters");
283+
SavedFilters = json is null ? null : JsonSerializer.Deserialize<List<FancyColumnFilter>>(json);
284+
}
285+
286+
private async Task SaveFiltersAsync(IReadOnlyList<FancyColumnFilter> filters) =>
287+
await JS.InvokeVoidAsync("localStorage.setItem", "people-filters", JsonSerializer.Serialize(filters));
288+
}
289+
```
290+
291+
`InitialColumnFilters` is applied once, so load the saved list before the table first renders. `localStorage` is not available during prerendering; in that case load it in `OnAfterRenderAsync` and render the table afterwards.
292+
251293
## Setup
252294

253295
To use `SoPro.FancyTable` in your Blazor application, include Bootstrap CSS and Bootstrap Icons in your app (`App.razor` / host page):
@@ -555,6 +597,7 @@ Global expand/collapse actions always operate on the full tree, not just on the
555597

556598
- Search shows matching nodes and their ancestors, so hits remain visible in context
557599
- Clearing the search restores the manual expand/collapse state from before the search
600+
- Column filters apply together with search: a node is shown only if it matches the search and the filters itself, and its ancestors are kept as the path to it
558601
- Sorting keeps the tree structure intact by sorting only within each sibling group
559602

560603
## Component Dependencies

0 commit comments

Comments
 (0)