Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Bugfixes (#101) #patch
Browse files Browse the repository at this point in the history
Better handling of null values
CustomSelect filter doesn't provide first value in WASM #97
Enum filter doesn't provide first value
  • Loading branch information
IvanJosipovic authored Apr 5, 2020
1 parent 4904be5 commit b5de1e0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/BlazorTable/Filters/CustomSelect.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;

namespace BlazorTable
Expand Down Expand Up @@ -97,6 +98,12 @@ public Expression<Func<TableItem, bool>> GetFilter()
public void AddSelect(string key, object value)
{
Items.Add(new KeyValuePair<string, object>(key, value));

if (FilterValue == null)
{
FilterValue = Items.FirstOrDefault().Value;
}

StateHasChanged();
}

Expand Down
5 changes: 5 additions & 0 deletions src/BlazorTable/Filters/EnumFilter.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ protected override void OnInitialized()
FilterValue = constantExpression.Value;
}
}

if (FilterValue == null)
{
FilterValue = Enum.GetValues(Column.Type.GetNonNullableType()).GetValue(0);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/BlazorTable/Filters/NumberFilter.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ protected override void OnInitialized()

public Expression<Func<TableItem, bool>> GetFilter()
{
if (Condition != NumberCondition.IsNull && Condition != NumberCondition.IsNotNull && string.IsNullOrEmpty(FilterValue))
{
return null;
}

return Condition switch
{
NumberCondition.IsEqualTo =>
Expand Down
5 changes: 5 additions & 0 deletions src/BlazorTable/Filters/StringFilter.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public Expression<Func<TableItem, bool>> GetFilter()
{
FilterText = FilterText?.Trim();

if (Condition != StringCondition.IsNullOrEmpty && Condition != StringCondition.IsNotNulOrEmpty && string.IsNullOrEmpty(FilterText))
{
return null;
}

return Condition switch
{
StringCondition.Contains =>
Expand Down

0 comments on commit b5de1e0

Please sign in to comment.