Skip to content

Commit 36b9a4e

Browse files
docs: fix column filter persistence example and document filter details
1 parent 4e02f1d commit 36b9a4e

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ https://www.nuget.org/packages/SoPro.FancyTable
3838
- Eight case-insensitive text operators: `Equals`, `NotEquals`, `Contains`, `NotContains`, `StartsWith`, `EndsWith`, `IsEmpty`, `IsNotEmpty`
3939
- Filters combine with AND across columns and with the active search
4040
- Filtered text comes from `SearchTextSelector`, falling back to `ValueSelector`
41+
- `Equals` and `NotEquals` compare trimmed text; the other operators use the value as typed
42+
- `IsEmpty` and `IsNotEmpty` take no value
43+
- Filters apply explicitly (Apply button or Enter); Esc or a click outside discards the draft
44+
- Every filter change resets the table to page 1
45+
- A hidden column keeps its filter; its restore button shows a funnel icon
46+
- `ColumnFiltersChanged` delivers the complete list in column definition order
47+
- A `Filterable` column needs a `ValueSelector` or `SearchTextSelector`; `CellTemplate`-only columns have empty filter text
48+
- Operator values are stable integers; use `JsonStringEnumConverter` if you prefer names in persisted JSON
49+
- Requires a browser with the HTML Popover API (Baseline since 2024)
4150
- Host-owned persistence through `InitialColumnFilters` and `ColumnFiltersChanged`
4251

4352
### Column layout
@@ -268,27 +277,38 @@ Mark columns with `Filterable = true`. The host persists the filters; the compon
268277
@inject IJSRuntime JS
269278
@using System.Text.Json
270279
271-
<FancyTable TItem="PersonRow"
272-
Items="People"
273-
Columns="PeopleColumns"
274-
InitialColumnFilters="SavedFilters"
275-
ColumnFiltersChanged="SaveFiltersAsync" />
280+
@if (filtersLoaded)
281+
{
282+
<FancyTable TItem="PersonRow"
283+
Items="People"
284+
Columns="PeopleColumns"
285+
InitialColumnFilters="SavedFilters"
286+
ColumnFiltersChanged="SaveFiltersAsync" />
287+
}
276288
277289
@code {
278290
private IReadOnlyList<FancyColumnFilter>? SavedFilters;
291+
private bool filtersLoaded;
279292
280-
protected override async Task OnInitializedAsync()
293+
protected override async Task OnAfterRenderAsync(bool firstRender)
281294
{
295+
if (!firstRender)
296+
{
297+
return;
298+
}
299+
282300
string? json = await JS.InvokeAsync<string?>("localStorage.getItem", "people-filters");
283301
SavedFilters = json is null ? null : JsonSerializer.Deserialize<List<FancyColumnFilter>>(json);
302+
filtersLoaded = true;
303+
StateHasChanged();
284304
}
285305
286306
private async Task SaveFiltersAsync(IReadOnlyList<FancyColumnFilter> filters) =>
287307
await JS.InvokeVoidAsync("localStorage.setItem", "people-filters", JsonSerializer.Serialize(filters));
288308
}
289309
```
290310

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.
311+
`InitialColumnFilters` is read once, on the table's first render, so load persisted filters before rendering the table. `localStorage` is only available after the first render (it is not during prerendering), which is why the example renders the table once `filtersLoaded` is set.
292312

293313
## Setup
294314

0 commit comments

Comments
 (0)