Skip to content

Commit

Permalink
remove redundant checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Dec 27, 2023
1 parent a42b83d commit 28a1b05
Showing 1 changed file with 25 additions and 55 deletions.
80 changes: 25 additions & 55 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public partial class DataGrid
private readonly Style _defaultHeaderStyle;
private readonly Style _defaultSortIconStyle;

private bool _isReloading;
private bool _isSortingAndPaginating;
private readonly object _reloadLock = new();
private readonly object _sortAndPaginateLock = new();
private IList<object>? _internalItems;
Expand Down Expand Up @@ -207,47 +205,33 @@ private void SortAndPaginate(SortData? sortData = null)
{
lock (_sortAndPaginateLock)
{
if (_isSortingAndPaginating)
if (ItemsSource is null)
{
return;
}

_isSortingAndPaginating = true;
sortData ??= SortedColumnIndex;

try
{
if (ItemsSource is null)
{
return;
}
var originalItems = ItemsSource.Cast<object>().ToList();

sortData ??= SortedColumnIndex;
IList<object> sortedItems;

var originalItems = ItemsSource.Cast<object>().ToList();

IList<object> sortedItems;

if (sortData != null && CanSort(sortData))
{
sortedItems = GetSortedItems(originalItems, sortData);
}
else
{
sortedItems = originalItems;
}
if (sortData != null && CanSort(sortData))
{
sortedItems = GetSortedItems(originalItems, sortData);
}
else
{
sortedItems = originalItems;
}

if (PaginationEnabled)
{
InternalItems = GetPaginatedItems(sortedItems).ToList();
}
else
{
InternalItems = sortedItems;
}
if (PaginationEnabled)
{
InternalItems = GetPaginatedItems(sortedItems).ToList();
}
finally
else
{
_isSortingAndPaginating = false;
InternalItems = sortedItems;
}
}
}
Expand Down Expand Up @@ -1201,33 +1185,19 @@ internal void Reload()
{
lock (_reloadLock)
{
if (_isReloading)
// Check if PageSizeList contains the new PageSize value, so that it shows in the dropdown
if (!PageSizeList.Contains(PageSize))
{
return;
PageSizeList.Add(PageSize);
OnPropertyChanged(nameof(PageSizeList));
OnPropertyChanged(nameof(PageSize));
}

_isReloading = true;
InitHeaderView();

try
{
// Check if PageSizeList contains the new PageSize value, so that it shows in the dropdown
if (!PageSizeList.Contains(PageSize))
{
PageSizeList.Add(PageSize);
OnPropertyChanged(nameof(PageSizeList));
OnPropertyChanged(nameof(PageSize));
}

InitHeaderView();

if (_internalItems is not null)
{
InternalItems = new List<object>(_internalItems);
}
}
finally
if (_internalItems is not null)
{
_isReloading = false;
InternalItems = new List<object>(_internalItems);
}
}
}
Expand Down

0 comments on commit 28a1b05

Please sign in to comment.