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
4 changes: 3 additions & 1 deletion src/ColumnFilterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public virtual IList<TableViewFilterItem> GetFilterItems(TableViewColumn column,
}));
}

collectionView.Source = (column.TableView.ItemsSource as IEnumerable) ?? Enumerable.Empty<object>();
collectionView.Source = (_tableView.IsHierarchicalEnabled
? (IEnumerable)_tableView.GetAllHierarchyItemsFlat().ToList()
: column.TableView.ItemsSource as IEnumerable) ?? Enumerable.Empty<object>();

var items = _tableView.ShowFilterItemsCount ?
GetFilterItemsWithCount(column, searchText, collectionView) :
Expand Down
34 changes: 34 additions & 0 deletions src/EventArgs/TableViewRowExpansionChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

namespace WinUI.TableView;

/// <summary>
/// Provides data for the <see cref="TableView.RowExpanded"/> and <see cref="TableView.RowCollapsed"/> events.
/// </summary>
public sealed class TableViewRowExpansionChangedEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="TableViewRowExpansionChangedEventArgs"/> class.
/// </summary>
public TableViewRowExpansionChangedEventArgs(object item, int index, bool isExpanded)
{
Item = item;
Index = index;
IsExpanded = isExpanded;
}

/// <summary>
/// Gets the item whose expansion state changed.
/// </summary>
public object Item { get; }

/// <summary>
/// Gets the index of the item in the display list.
/// </summary>
public int Index { get; }

/// <summary>
/// Gets a value indicating whether the item is now expanded.
/// </summary>
public bool IsExpanded { get; }
}
15 changes: 15 additions & 0 deletions src/ItemsSource/CollectionView.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ namespace WinUI.TableView;

partial class CollectionView
{
/// <summary>
/// Gets or sets a value indicating whether sort descriptions should be ignored when
/// rebuilding the view. Set by <see cref="TableView"/> when hierarchical mode is active
/// so that per-level sorting is applied during flattening instead of globally.
/// </summary>
internal bool BypassSort { get; set; }

/// <summary>
/// Gets or sets a value indicating whether filter descriptions should be ignored when
/// rebuilding the view. Set by <see cref="TableView"/> when hierarchical mode is active
/// so that subtree-aware filtering is applied during hierarchy flattening instead of
/// the flat per-item filter used in normal mode.
/// </summary>
internal bool BypassFilter { get; set; }

/// <summary>
/// Gets or sets the source collection.
/// </summary>
Expand Down
28 changes: 16 additions & 12 deletions src/ItemsSource/CollectionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void OnItemPropertyChanged(object? item, PropertyChangedEventArgs e)
return;
}

if (FilterDescriptions.Any(fd => string.IsNullOrEmpty(fd.PropertyName) || fd.PropertyName == e.PropertyName))
if (!BypassFilter && FilterDescriptions.Any(fd => string.IsNullOrEmpty(fd.PropertyName) || fd.PropertyName == e.PropertyName))
{
var filterResult = FilterDescriptions.All(x => x.Predicate(item));
var viewIndex = _view.IndexOf(item);
Expand Down Expand Up @@ -318,7 +318,7 @@ private void HandleSourceChanged()

if (Source is not null)
{
if (FilterDescriptions.Count > 0)
if (!BypassFilter && FilterDescriptions.Count > 0)
{
foreach (var item in Source)
{
Expand All @@ -331,7 +331,7 @@ private void HandleSourceChanged()
_view.AddRange(_source.OfType<object>());
}

if (SortDescriptions.Count > 0)
if (SortDescriptions.Count > 0 && !BypassSort)
_view.Sort(this);
}

Expand All @@ -344,6 +344,8 @@ private void HandleSourceChanged()
/// </summary>
private void HandleFilterChanged()
{
if (BypassFilter) return;

if (FilterDescriptions.Count > 0)
{
for (var index = 0; index < _view.Count; index++)
Expand Down Expand Up @@ -384,24 +386,26 @@ private void HandleFilterChanged()
/// </summary>
private void HandleSortChanged()
{
if (SortDescriptions.Count > 0)
if (!BypassSort)
{
_view.Sort(this);
}
else
{
HandleSourceChanged();
}
if (SortDescriptions.Count > 0)
_view.Sort(this);
else
HandleSourceChanged();

OnVectorChanged(new VectorChangedEventArgs(CollectionChange.Reset));
OnVectorChanged(new VectorChangedEventArgs(CollectionChange.Reset));
}
// When BypassSort is true the external caller (TableView) handles the full
// rebuild via RebuildHierarchyView(). Firing VectorChanged here would trigger
// a stale RebuildDisplayedItems() before the hierarchy is re-flattened.
}

/// <summary>
/// Handles the addition of an item to the collection.
/// </summary>
private bool HandleItemAdded(int newStartingIndex, object? newItem, int? viewIndex = null)
{
if (!FilterDescriptions.All(x => x.Predicate(newItem)))
if (!BypassFilter && !FilterDescriptions.All(x => x.Predicate(newItem)))
{
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Strings/en-US/WinUI.TableView.resw
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,10 @@
<data name="Copy" xml:space="preserve">
<value>Copy</value>
</data>
<data name="ExpandRow" xml:space="preserve">
<value>Expand row</value>
</data>
<data name="CollapseRow" xml:space="preserve">
<value>Collapse row</value>
</data>
</root>
28 changes: 27 additions & 1 deletion src/TableView.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,30 @@ protected internal virtual void OnColumnReordered(TableViewColumnReorderedEventA
{
ColumnReordered?.Invoke(this, args);
}
}

/// <summary>
/// Occurs when a row is expanded in hierarchical mode.
/// </summary>
public event EventHandler<TableViewRowExpansionChangedEventArgs>? RowExpanded;

/// <summary>
/// Occurs when a row is collapsed in hierarchical mode.
/// </summary>
public event EventHandler<TableViewRowExpansionChangedEventArgs>? RowCollapsed;

/// <summary>
/// Called when a row is expanded.
/// </summary>
protected internal virtual void OnRowExpanded(TableViewRowExpansionChangedEventArgs args)
{
RowExpanded?.Invoke(this, args);
}

/// <summary>
/// Called when a row is collapsed.
/// </summary>
protected internal virtual void OnRowCollapsed(TableViewRowExpansionChangedEventArgs args)
{
RowCollapsed?.Invoke(this, args);
}
}
Loading
Loading