Skip to content

Commit

Permalink
Fix sort options in the BeforeRangeSort not being the same as those u…
Browse files Browse the repository at this point in the history
…sed to sort the range.
  • Loading branch information
anmcgrath committed Jun 2, 2024
1 parent bc4e9a0 commit aaba087
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/BlazorDatasheet.Core/Commands/SortRangeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public class SortRangeCommand : IUndoableCommand
/// <param name="region">The region to sort</param>
/// <param name="sortOptions">The column sort options, if null the default sort (sort on column 0 ascending) will be used.
/// If two column values are equal, then the next option will be used for the sort, equivalent to a ThenBy</param>
public SortRangeCommand(IRegion region, List<ColumnSortOptions>? sortOptions = null)
public SortRangeCommand(IRegion region, List<ColumnSortOptions> sortOptions = null)
{
_region = region;
_sortOptions = sortOptions ?? new List<ColumnSortOptions>()
{ new(0, true) };
_sortOptions = sortOptions;
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/BlazorDatasheet.Core/Data/Sheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ public void SortRange(IRegion? region, List<ColumnSortOptions>? sortOptions = nu
{
if (region == null)
return;

sortOptions ??= [new ColumnSortOptions(0, true)];

var beforeArgs = new BeforeRangeSortEventArgs(region, sortOptions);
BeforeRangeSort?.Invoke(this, beforeArgs);
var cmd = new SortRangeCommand(region, sortOptions);
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorDatasheet.Core/Events/BeforeRangeSortEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace BlazorDatasheet.Core.Events;
public class BeforeRangeSortEventArgs : CancelEventArgs
{
public IRegion Region { get; }
public IList<ColumnSortOptions>? SortOptions { get; }
public IList<ColumnSortOptions> SortOptions { get; }

public BeforeRangeSortEventArgs(IRegion region, IList<ColumnSortOptions>? sortOptions)
public BeforeRangeSortEventArgs(IRegion region, IList<ColumnSortOptions> sortOptions)
{
Region = region;
SortOptions = sortOptions;
Expand Down
1 change: 1 addition & 0 deletions test/BlazorDatasheet.Test/SheetTests/SheetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void Cancel_Before_Range_Sort_Cancels_Sorting()
sheet.BeforeRangeSort += (sender, args) =>
{
args.Cancel = true;
args.SortOptions.Should().NotBeNull();
};

sheet.SortRange(new ColumnRegion(0));
Expand Down

0 comments on commit aaba087

Please sign in to comment.