From 6435194e8d117df5f18c1e0a3604049a0c4eb4c6 Mon Sep 17 00:00:00 2001 From: Arne <5349088+ProblemSolved@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:21:46 +1000 Subject: [PATCH] Fixed Mud DataTable sorting issue. Nullable column can have a null value and these rows will not always be sorted on top. --- .../Binding/SortExpressionComparer.cs | 8 ++++++-- src/global.json | 20 +++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/DynamicData/Binding/SortExpressionComparer.cs b/src/DynamicData/Binding/SortExpressionComparer.cs index 9edfb0364..82087fc24 100644 --- a/src/DynamicData/Binding/SortExpressionComparer.cs +++ b/src/DynamicData/Binding/SortExpressionComparer.cs @@ -52,14 +52,18 @@ public int Compare(T? x, T? y) continue; } + // In case the column in Mud's DataTable is of a Nullable type all the rows with a Null value will end-up on top. + // This fixes the issue and either sorts them to the top or the bottom in accordance with the SortDirection. if (xValue is null) { - return -1; + // return -1; original line of code + return (item.Direction == SortDirection.Ascending) ? -int.MaxValue : int.MaxValue; } if (yValue is null) { - return 1; + // return 1; original line of code + return (item.Direction == SortDirection.Ascending) ? int.MaxValue : -int.MaxValue; } var result = xValue.CompareTo(yValue); diff --git a/src/global.json b/src/global.json index bb0671aa6..3f54f965a 100644 --- a/src/global.json +++ b/src/global.json @@ -1,10 +1,10 @@ -{ - "sdk": { - "version": "8.0.101", - "rollForward": "latestMinor", - "allowPrerelease": true - }, - "msbuild-sdks": { - "MSBuild.Sdk.Extras": "3.0.44" - } -} +//{ +// "sdk": { +// "version": "8.0.101", +// "rollForward": "latestMinor", +// "allowPrerelease": true +// }, +// "msbuild-sdks": { +// "MSBuild.Sdk.Extras": "3.0.44" +// } +//}