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
21 changes: 21 additions & 0 deletions Maui.DataGrid/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,41 @@
<Right>lib/net9.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Maui.DataGrid.DataGridColumn.SortPropertyNameProperty</Target>
<Left>lib/net9.0/Maui.DataGrid.dll</Left>
<Right>lib/net9.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGridColumn.get_Padding</Target>
<Left>lib/net9.0/Maui.DataGrid.dll</Left>
<Right>lib/net9.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGridColumn.get_SortPropertyName</Target>
<Left>lib/net9.0/Maui.DataGrid.dll</Left>
<Right>lib/net9.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGridColumn.set_Padding(Microsoft.Maui.Thickness)</Target>
<Left>lib/net9.0/Maui.DataGrid.dll</Left>
<Right>lib/net9.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Maui.DataGrid.DataGridColumn.set_SortPropertyName(System.String)</Target>
<Left>lib/net9.0/Maui.DataGrid.dll</Left>
<Right>lib/net9.0/Maui.DataGrid.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>PKV006</DiagnosticId>
<Target>net8.0</Target>
Expand Down
8 changes: 6 additions & 2 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,10 @@ private IEnumerable<object> GetSortedItems(IList<object> unsortedItems, SortData

IEnumerable<object> items;

string sortPropertyName = string.IsNullOrEmpty(_sortedColumn.SortPropertyName)
? _sortedColumn.PropertyName
: _sortedColumn.SortPropertyName;

switch (sortData.Order)
{
case SortingOrder.Ascendant:
Expand All @@ -1479,15 +1483,15 @@ private IEnumerable<object> GetSortedItems(IList<object> unsortedItems, SortData
#else
_ = _sortedColumn.SortingIcon.RotateTo(0);
#endif
items = unsortedItems.OrderBy(x => x.GetValueByPath(_sortedColumn.PropertyName));
items = unsortedItems.OrderBy(x => x.GetValueByPath(sortPropertyName));
break;
case SortingOrder.Descendant:
#if NET10_0_OR_GREATER
_ = _sortedColumn.SortingIcon.RotateToAsync(180);
#else
_ = _sortedColumn.SortingIcon.RotateTo(180);
#endif
items = unsortedItems.OrderByDescending(x => x.GetValueByPath(_sortedColumn.PropertyName));
items = unsortedItems.OrderByDescending(x => x.GetValueByPath(sortPropertyName));
break;
case SortingOrder.None:
return unsortedItems;
Expand Down
20 changes: 19 additions & 1 deletion Maui.DataGrid/DataGridColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ public sealed class DataGridColumn : BindableObject, IDefinition
}
});

/// <summary>
/// Gets or sets the name of the sort property associated with the column.
/// </summary>
public static readonly BindableProperty SortPropertyNameProperty =
BindablePropertyExtensions.Create<DataGridColumn, string>();

#endregion Bindable Properties

#region Fields
Expand Down Expand Up @@ -443,6 +449,15 @@ public Style HeaderFilterStyle
set => SetValue(HeaderFilterStyleProperty, value);
}

/// <summary>
/// Gets or sets sort property name to bind in the object.
/// </summary>
public string SortPropertyName
{
get => (string)GetValue(SortPropertyNameProperty);
set => SetValue(SortPropertyNameProperty, value);
}

internal Polygon SortingIcon { get; } = new();

internal Entry FilterTextbox { get; } = new() { Placeholder = "Filter" };
Expand All @@ -466,6 +481,8 @@ public Style HeaderFilterStyle

internal Type? DataType { get; private set; }

internal Type? SortDataType { get; private set; }

internal DataGrid? DataGrid { get; set; }

internal ColumnDefinition? ColumnDefinition
Expand Down Expand Up @@ -502,7 +519,7 @@ public bool IsSortable()
}
else if (DataType is not null)
{
_isSortable = typeof(IComparable).IsAssignableFrom(DataType);
_isSortable = typeof(IComparable).IsAssignableFrom(SortDataType);
}

return _isSortable ??= false;
Expand Down Expand Up @@ -544,6 +561,7 @@ internal void InitializeDataType()
}

DataType = rowDataType?.GetPropertyTypeByPath(PropertyName);
SortDataType = string.IsNullOrEmpty(SortPropertyName) ? DataType : rowDataType?.GetPropertyTypeByPath(SortPropertyName);
}
catch (Exception ex)
when (ex is NotSupportedException or ArgumentNullException or InvalidCastException)
Expand Down
24 changes: 12 additions & 12 deletions Maui.DataGrid/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
},
"Microsoft.DotNet.ILCompiler": {
"type": "Direct",
"requested": "[10.0.2, )",
"resolved": "10.0.2",
"contentHash": "0g8tazNW4q0anSYNl1hnaHGc7+BQXwpNBMx3d5T3JboOVzz4OXZgqbuoBYfn60VtDFtBMNVS2Kfopelpo2pLZA=="
"requested": "[10.0.3, )",
"resolved": "10.0.3",
"contentHash": "H9kuN7egYzW5JAn5CMK8uJdJDVnPEDpZHzjOXyz1iAgvxNgVSoAiTNkCBeY2jaXcHlruF5fRUrZoUHUHXftDDA=="
},
"Microsoft.Maui.Controls": {
"type": "Direct",
Expand All @@ -28,9 +28,9 @@
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[10.0.2, )",
"resolved": "10.0.2",
"contentHash": "sXdDtMf2qcnbygw9OdE535c2lxSxrZP8gO4UhDJ0xiJbl1wIqXS1OTcTDFTIJPOFd6Mhcm8gPEthqWGUxBsTqw=="
"requested": "[10.0.8, )",
"resolved": "10.0.8",
"contentHash": "dVbSXGIFNR5nZcv2tOLoWI+a9T4jtFd77IYjuND+QVe360qWgAF7H0WtoopYhRw/+SgpGUTyrkrh+65+ClNnfw=="
},
"StyleCop.Analyzers": {
"type": "Direct",
Expand Down Expand Up @@ -210,9 +210,9 @@
},
"Microsoft.DotNet.ILCompiler": {
"type": "Direct",
"requested": "[9.0.12, )",
"resolved": "9.0.12",
"contentHash": "6RjjgSgfaKgnhNepPhfKQFB/g2TzbqmuOR29jWuOfeM5HMIyELd2T/OQC6P7gKEaOMYp3iYwt21dyYgWVpqnVQ=="
"requested": "[9.0.13, )",
"resolved": "9.0.13",
"contentHash": "HjOJCDy5GcOzkOeQuBLgbu8nUBvoZIZ+yA8SkDbb00PLAtYlRyZyfjjyNuhj3C0k+aliAV1oUCzVXqRQFxeI8g=="
},
"Microsoft.Maui.Controls": {
"type": "Direct",
Expand All @@ -228,9 +228,9 @@
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[9.0.12, )",
"resolved": "9.0.12",
"contentHash": "StA3kyImQHqDo8A8ZHaSxgASbEuT5UIqgeCvK5SzUPj//xE1QSys421J9pEs4cYuIVwq7CJvWSKxtyH7aPr1LA=="
"requested": "[9.0.16, )",
"resolved": "9.0.16",
"contentHash": "ccPBYGLPJt8DeJTUzQ0JzOh/iuUAgnjayU63PokVywAhUOx+dzDKSPTL7AG94U/VpvNXflTT2AjsFAIF1+bXBw=="
},
"StyleCop.Analyzers": {
"type": "Direct",
Expand Down