Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
## [Unreleased]

### Added
- Per-column filter settings (#373) on `KumikoColumn`, which is a Core object, so MAUI and Uno XAML and code get them alike. `AllowedTextFilterOperators`, `AllowedNumericFilterOperators` and `AllowedDateFilterOperators` list the operators the filter popup offers, in order (null offers all), and `AllowedFilterOperatorsString` is the XAML form (`"Equals,StartsWith"`, parsed for the column's type; an unknown name throws at assignment). `DefaultTextFilterOperator`, `DefaultNumericFilterOperator` and `DefaultDateFilterOperator` set the operator a new condition starts with, and `CreateDefaultFilterCondition()` returns a condition using them. `FilterCompareOptions` replaces the source's `StringCompareOptions` for that column's conditions and value list (for example `None` to match case-sensitively), in foreground and background rebuilds and in `GetUniqueColumnValues`, without affecting other columns. The restriction is for the UI only: conditions set from code with any operator still apply, and the popup keeps listing the operator of a condition the column already has. (#373)
- Scroll bars: the grid draws a vertical bar at the right edge of the scrolling rows and a horizontal bar across the scrolling columns. `VerticalScrollBarVisibility` and `HorizontalScrollBarVisibility` (`KumikoScrollBarVisibility`: `Auto`, the default, an overlay shown while the grid scrolls or a mouse rests over it that then fades; `Always`; `Never`) on `KumikoStyle` and on both grids, plus `ScrollBarThickness`, `ScrollBarExpandedThickness`, `ScrollBarMinThumbLength`, `ScrollBarThumbColor` and `ScrollBarTrackColor`. With a mouse or a pen a bar expands on hover, its thumb drags and its track pages (repeating while held); a finger pans through it. New `HitRegion` values `VerticalScrollBarThumb`, `VerticalScrollBarTrack`, `HorizontalScrollBarThumb` and `HorizontalScrollBarTrack`. A mouse or pen press within 10 px of the rows' right or bottom edge now lands on the bar instead of the cell under it (#316).
- A built-in column header menu, drawn by the grid so it looks the same on every platform and opens at the pointer (#319). Turn it on with `IsColumnMenuEnabled` (MAUI and Uno, off by default): a right click or a long press on a column header, the optional header menu button (`ShowColumnMenuButton`) or the Menu key / Shift+F10 opens it with sort ascending, sort descending, clear sort, filter, group by this column or ungroup, hide and auto-fit width, as far as the grid and the column allow. `ColumnMenuOpening` (`KumikoColumnMenuOpeningEventArgs`) lets an app remove, reorder or add items or cancel the menu, `ShowColumnMenu(column)` opens it in code, and its texts are new `KumikoStrings` members. `ContextMenuRequested` is raised first and the menu opens only when no handler set the new `KumikoContextRequestedEventArgs.Handled`, so an app that shows its own header menu sets it before turning the built-in one on. The menu is a reusable `DrawnMenu` of `DrawnMenuItem`s (separators, icons, check marks, disabled items, keyboard navigation with typeahead, scrolling, screen-reader announcements). Also new: `KumikoKey.ContextMenu`, `HitRegion.HeaderMenuButton`, `KumikoIcon.ColumnMenu` and `ShowColumnMenuButton` on `KumikoRenderer`, `KumikoInputController` and `KumikoHitTester`.
- Incremental "load more" loading (#318): the grid asks for the next batch as the user nears the end of the loaded rows, draws a loading row after the last row while it waits, and an error row with Retry when a batch fails (never retried automatically). One batch runs at a time; replacing or resetting the items, `Detach` and `Dispose` cancel it. Sources: `IKumikoIncrementalSource` (detected on the items or set through `IncrementalSource`), the ready-made `KumikoIncrementalCollection<T>`, an MVVM `LoadMoreCommand` with two-way `IsLoadingMore` and `LoadMoreErrorText`, and on Uno an `ISupportIncrementalLoading` items source. Both hosts add `LoadMoreMode` (Automatic, Manual, None), `LoadMoreThreshold`, `LoadMoreBatchSize`, the read-only `LoadMoreState`, the `LoadMoreRequested` and `LoadMoreCompleted` events, `LoadMoreAsync` and `ResetLoadMore`; Core adds `KumikoSource.IncrementalLoading` (`KumikoIncrementalLoader`), `HitRegion.LoadMoreRow`, the `KumikoStyle.LoadMore*` members, the `KumikoStrings.LoadMore*` and `AnnounceLoadMore*` strings and `KumikoAnnouncements.LoadMoreStarted`/`LoadMoreCompleted`. A multi-item collection `Add` now raises one `ViewChanged` `Insert` (no sort, grouping or summary) instead of a rebuild.
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,15 @@ Each column header with `AllowFiltering` (the default) shows a filter icon. Tapp

OK applies both pages, combined with And: the checked values and the conditions. A page you did not change keeps what the filter had, so OK on Values keeps the conditions and OK on Conditions keeps the checked values, and the tab of the page not shown has a dot while it holds criteria. A value that does not parse keeps the popup open with the `EnterNumber` or `EnterDate` message. The popup opens on Conditions when the column's filter has a condition. Set `KumikoColumn.AllowConditionFilter` to false to show only the values for a column; Boolean, Image and Template columns have no Conditions page.

Shape the conditions per column with `KumikoColumn` settings. `AllowedFilterOperatorsString="Equals,StartsWith"` (or `AllowedTextFilterOperators`, `AllowedNumericFilterOperators`, `AllowedDateFilterOperators` from code) limits the operators the popup lists, in that order; `DefaultTextFilterOperator`, `DefaultNumericFilterOperator` and `DefaultDateFilterOperator` choose the operator a new condition starts with (`CreateDefaultFilterCondition()` builds one); and `FilterCompareOptions="None"` makes that column's conditions and value list case-sensitive while other columns keep the grid's `StringCompareOptions`. The operator lists restrict the popup only: a condition set from code with another operator still applies.

```xml
<core:KumikoColumn Header="Code" PropertyName="Code"
AllowedFilterOperatorsString="Equals,StartsWith"
DefaultTextFilterOperator="StartsWith"
FilterCompareOptions="None" />
```

The value list scrolls by drag, mouse wheel, its scrollbar, and Up/Down, Page Up/Page Down, Space, Enter and Escape. Tab and Shift+Tab move between the switch (Left/Right change the page), the search box or the operators and values, And/Or (Space switches) and the buttons; Enter applies, and Escape closes an open operator list or calendar before the popup, as does a tap outside it. The value boxes take text like the search box (input methods, the soft keyboard, the clipboard), and a screen reader hears the page, the operator and where Tab moved (with the grid's `AnnounceChanges` on). Filters on several columns combine. The filter icon is drawn in `FilterActiveIconColor` while the column has a filter.

From code, filter by predicate or per column:
Expand Down
18 changes: 15 additions & 3 deletions src/KumikoUI.Core/Components/DrawnFilterPopup.Conditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,15 @@ private void InitConditions()

if (_kind == FilterConditionKind.None) return;

// The column's allowed operators, plus those of conditions it already has (set from code, #373).
var existing = _column.ActiveFilter;
_operatorChoices = FilterConditionTypes.Operators(_kind, _column, new[]
{
existing?.Condition1 is { } c1 ? FilterConditionTypes.OperatorOf(_kind, c1) : null,
existing?.Condition2 is { } c2 ? FilterConditionTypes.OperatorOf(_kind, c2) : null,
});
var items = new List<DrawnComboBoxItem>();
foreach (var op in FilterConditionTypes.Operators(_kind))
foreach (var op in _operatorChoices)
items.Add(new DrawnComboBoxItem(Strings.FilterOperatorLabel(op), op));
_operators[0].SetItems(items);
_operators[1].SetItems(items);
Expand All @@ -160,6 +167,9 @@ private void InitConditions()
}
}

/// <summary>The operators the drop-downs list: the column's allowed ones and those of conditions it already has.</summary>
private IReadOnlyList<object> _operatorChoices = Array.Empty<object>();

/// <summary>Shows the column's conditions: the first in row 1, the second in row 2, each with the default operator when absent.</summary>
private void LoadConditions()
{
Expand All @@ -173,8 +183,10 @@ private void LoadConditions()

private void LoadRow(int row, FilterCondition? condition)
{
var operators = FilterConditionTypes.Operators(_kind);
object? op = condition != null ? FilterConditionTypes.OperatorOf(_kind, condition) : null;
var operators = _operatorChoices;
object? op = condition != null
? FilterConditionTypes.OperatorOf(_kind, condition)
: FilterConditionTypes.DefaultOperator(_kind, _column);
int index = 0;
for (int i = 0; i < operators.Count; i++)
if (Equals(operators[i], op)) index = i;
Expand Down
75 changes: 75 additions & 0 deletions src/KumikoUI.Core/Components/FilterConditionTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,81 @@
_ => FilterConditionKind.None,
};

/// <summary>
/// The operator family of a column type for the per-column operator settings: like <see cref="KindOf(KumikoColumnType)"/>,
/// and the date family also covers DateTime and Time columns, whose conditions evaluate the date operators.
/// </summary>
/// <param name="type">The column type.</param>
internal static FilterConditionKind OperatorKindOf(KumikoColumnType type) => type switch
{
KumikoColumnType.DateTime or KumikoColumnType.Time => FilterConditionKind.Date,
_ => KindOf(type),
};

/// <summary>
/// The operators the drop-down of <paramref name="kind"/> lists for <paramref name="column"/>: the column's allowed
/// operators in its order, or all of them when it sets none. Operators in <paramref name="keep"/> (those of
/// conditions the column already has) are added at the end when missing, so editing never changes them silently.
/// </summary>
/// <param name="kind">The condition editor.</param>
/// <param name="column">The column.</param>
/// <param name="keep">Boxed operators that must stay listed, or null.</param>
internal static IReadOnlyList<object> Operators(FilterConditionKind kind, KumikoColumn column, IEnumerable<object?>? keep = null)
{
IReadOnlyList<object> all = Operators(kind);
List<object>? allowed = kind switch
{
FilterConditionKind.Text => Boxed(column.AllowedTextFilterOperators),
FilterConditionKind.Number => Boxed(column.AllowedNumericFilterOperators),
FilterConditionKind.Date => Boxed(column.AllowedDateFilterOperators),
_ => null,
};
if (allowed == null) return all;
if (keep != null)
foreach (var op in keep)
if (op != null && !allowed.Contains(op)) allowed.Add(op);
Comment on lines +87 to +88
return allowed;
}

private static List<object>? Boxed<T>(IReadOnlyList<T>? list) where T : struct, Enum
{
if (list == null || list.Count == 0) return null;
var result = new List<object>(list.Count);
foreach (var op in list)
if (!result.Contains(op)) result.Add(op);
Comment on lines +96 to +97
return result;
}

/// <summary>
/// The operator a new condition of <paramref name="kind"/> starts with for <paramref name="column"/>: its default
/// operator, or the stock one (Contains, Equals, Equals) when it sets none, or the first allowed operator when the
/// column does not allow the stock one. Boxed; null for a kind without conditions.
/// </summary>
/// <param name="kind">The condition editor.</param>
/// <param name="column">The column.</param>
internal static object? DefaultOperator(FilterConditionKind kind, KumikoColumn column)
{
object? preferred = kind switch
{
FilterConditionKind.Text => column.DefaultTextFilterOperator ?? TextFilterOperator.Contains,
FilterConditionKind.Number => column.DefaultNumericFilterOperator ?? NumericFilterOperator.Equals,
FilterConditionKind.Date => column.DefaultDateFilterOperator ?? DateFilterOperator.Equals,
_ => null,
};
if (kind == FilterConditionKind.None) return null;
// An explicit default is honored as given (it also applies to conditions created in code); only the stock
// one gives way to the first allowed operator.
bool explicitDefault = kind switch
{
FilterConditionKind.Text => column.DefaultTextFilterOperator.HasValue,
FilterConditionKind.Number => column.DefaultNumericFilterOperator.HasValue,
_ => column.DefaultDateFilterOperator.HasValue,
};
if (explicitDefault) return preferred;
var operators = Operators(kind, column);
return operators.Contains(preferred!) ? preferred : operators[0];
}

/// <summary>The condition editor of a column: none when it turns condition filters off.</summary>
/// <param name="column">The column.</param>
internal static FilterConditionKind KindOf(KumikoColumn column) =>
Expand Down
9 changes: 6 additions & 3 deletions src/KumikoUI.Core/Models/FilterDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ public FilterDescription(KumikoColumn column)

/// <summary>
/// Evaluate this filter against a cell value and its display text, with the current culture and
/// case-insensitive text rules (<see cref="KumikoComparer.Default"/>).
/// case-insensitive text rules (<see cref="KumikoComparer.Default"/>), or the column's <see cref="KumikoColumn.FilterCompareOptions"/>.
/// </summary>
public bool Evaluate(object? cellValue, string displayText) =>
EvaluateWith(cellValue, displayText, Column.ResolveFilterComparer(KumikoComparer.Default));

private bool EvaluateWith(object? cellValue, string displayText, KumikoComparer comparer) =>
Evaluate(cellValue, displayText, SelectedValues is { } selected
? new HashSet<string>(selected, KumikoComparer.Default.TextComparer)
: null, KumikoComparer.Default);
? new HashSet<string>(selected, comparer.TextComparer)
: null, comparer);

/// <summary>
/// A copy whose conditions are copies too, for a view build on a worker (#254): later changes to this
Expand Down
Loading
Loading