From 4d95348d83897e338a5c1ede047c3c8491e73192 Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Fri, 6 Mar 2020 20:02:25 -0800 Subject: [PATCH 1/9] Added redirect --- src/BlazorTable.Sample.Wasm/wwwroot/_redirects | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/BlazorTable.Sample.Wasm/wwwroot/_redirects diff --git a/src/BlazorTable.Sample.Wasm/wwwroot/_redirects b/src/BlazorTable.Sample.Wasm/wwwroot/_redirects new file mode 100644 index 00000000..50a46335 --- /dev/null +++ b/src/BlazorTable.Sample.Wasm/wwwroot/_redirects @@ -0,0 +1 @@ +/* /index.html 200 \ No newline at end of file From 3e7a9294420441455868de6366be7c1890b008ec Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Fri, 6 Mar 2020 22:42:22 -0800 Subject: [PATCH 2/9] update table only if filter exists --- src/BlazorTable/Components/FilterManager.razor.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/BlazorTable/Components/FilterManager.razor.cs b/src/BlazorTable/Components/FilterManager.razor.cs index e05df14f..f508deef 100644 --- a/src/BlazorTable/Components/FilterManager.razor.cs +++ b/src/BlazorTable/Components/FilterManager.razor.cs @@ -28,8 +28,11 @@ private void ApplyFilter() private void ClearFilter() { Column.ToggleFilter(); - Column.Filter = null; - Column.Table.Update(); + if (Column.Filter != null) + { + Column.Filter = null; + Column.Table.Update(); + } } } } From 8f9e26261f0b74c7a6a2cce79fce908cf39b1c1a Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Sat, 7 Mar 2020 00:18:17 -0800 Subject: [PATCH 3/9] fixed Custom IFilters not working --- src/BlazorTable/Components/Column.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BlazorTable/Components/Column.razor b/src/BlazorTable/Components/Column.razor index 7e101498..5ce141ad 100644 --- a/src/BlazorTable/Components/Column.razor +++ b/src/BlazorTable/Components/Column.razor @@ -14,7 +14,7 @@ @if (this.CustomIFilters != null) { - this.CustomIFilters(this); + @this.CustomIFilters(this); } From 40e5fb93daa6acf3b1f60858a2e701b5c37998ae Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Sat, 7 Mar 2020 00:19:05 -0800 Subject: [PATCH 4/9] cleanup --- .../Components/EmptyDataTemplate.razor.cs | 1 - src/BlazorTable/Components/FilterManager.razor.cs | 14 ++++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/BlazorTable/Components/EmptyDataTemplate.razor.cs b/src/BlazorTable/Components/EmptyDataTemplate.razor.cs index 4fb4cd41..e01e57ec 100644 --- a/src/BlazorTable/Components/EmptyDataTemplate.razor.cs +++ b/src/BlazorTable/Components/EmptyDataTemplate.razor.cs @@ -5,7 +5,6 @@ namespace BlazorTable /// /// Child content for empty dataset /// - /// public partial class EmptyDataTemplate { /// diff --git a/src/BlazorTable/Components/FilterManager.razor.cs b/src/BlazorTable/Components/FilterManager.razor.cs index f508deef..46ce23ff 100644 --- a/src/BlazorTable/Components/FilterManager.razor.cs +++ b/src/BlazorTable/Components/FilterManager.razor.cs @@ -5,21 +5,26 @@ namespace BlazorTable { public partial class FilterManager { - [CascadingParameter(Name = "Column")] public IColumn Column { get; set; } + [CascadingParameter(Name = "Column")] + public IColumn Column { get; set; } - [Parameter] public RenderFragment ChildContent { get; set; } + [Parameter] + public RenderFragment ChildContent { get; set; } - [Inject] public ILogger> Logger { get; set; } + [Inject] + public ILogger> Logger { get; set; } private void ApplyFilter() { Column.ToggleFilter(); + if (Column.FilterControl != null) { Column.Filter = Column.FilterControl.GetFilter(); Column.Table.Update(); Column.Table.FirstPage(); - } else + } + else { Logger.LogInformation("Filter is null"); } @@ -28,6 +33,7 @@ private void ApplyFilter() private void ClearFilter() { Column.ToggleFilter(); + if (Column.Filter != null) { Column.Filter = null; From 1a9675f822fe6e24024018b34e50a256f642cc90 Mon Sep 17 00:00:00 2001 From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com> Date: Sat, 7 Mar 2020 00:21:50 -0800 Subject: [PATCH 5/9] simplified condition --- src/BlazorTable/Filters/BooleanFilter.razor | 2 +- src/BlazorTable/Filters/DateFilter.razor | 2 +- src/BlazorTable/Filters/EnumFilter.razor | 4 ++-- src/BlazorTable/Filters/NumberFilter.razor | 2 +- src/BlazorTable/Filters/StringFilter.razor | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BlazorTable/Filters/BooleanFilter.razor b/src/BlazorTable/Filters/BooleanFilter.razor index d9ef07ae..bc287066 100644 --- a/src/BlazorTable/Filters/BooleanFilter.razor +++ b/src/BlazorTable/Filters/BooleanFilter.razor @@ -1,7 +1,7 @@ @namespace BlazorTable @typeparam TableItem -@if (FilterTypes.Contains(Column.Type.GetNonNullableType())) +@if (Column.FilterControl == this) { @foreach (var option in (NumberCondition[])Enum.GetValues(typeof(NumberCondition))) diff --git a/src/BlazorTable/Filters/EnumFilter.razor b/src/BlazorTable/Filters/EnumFilter.razor index 20dda537..791825dc 100644 --- a/src/BlazorTable/Filters/EnumFilter.razor +++ b/src/BlazorTable/Filters/EnumFilter.razor @@ -1,7 +1,7 @@ @namespace BlazorTable @typeparam TableItem -@if (Column.Type.GetNonNullableType().IsEnum) +@if (Column.FilterControl == this) { - + @if (Condition != EnumCondition.IsNull && Condition != EnumCondition.IsNotNull) { @foreach (var option in (NumberCondition[])Enum.GetValues(typeof(NumberCondition))) diff --git a/src/BlazorTable/Filters/StringFilter.razor b/src/BlazorTable/Filters/StringFilter.razor index 700f15e2..ae3cc211 100644 --- a/src/BlazorTable/Filters/StringFilter.razor +++ b/src/BlazorTable/Filters/StringFilter.razor @@ -1,7 +1,7 @@ @namespace BlazorTable @typeparam TableItem -@if (Column.Type == FilterType) +@if (Column.FilterControl == this) { + @foreach (CustomSelectCondition option in Enum.GetValues(typeof(CustomSelectCondition))) + { + + } + + + @if (Condition != CustomSelectCondition.IsNull && Condition != CustomSelectCondition.IsNotNull) + { + + } +} + + + @ChildContent + \ No newline at end of file diff --git a/src/BlazorTable/Filters/CustomSelect.razor.cs b/src/BlazorTable/Filters/CustomSelect.razor.cs new file mode 100644 index 00000000..14ca8e03 --- /dev/null +++ b/src/BlazorTable/Filters/CustomSelect.razor.cs @@ -0,0 +1,118 @@ +using Microsoft.AspNetCore.Components; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Globalization; +using System.Linq.Expressions; + +namespace BlazorTable +{ + public partial class CustomSelect : IFilter, ICustomSelect + { + [CascadingParameter(Name = "Column")] + public IColumn Column { get; set; } + + [Parameter] + public RenderFragment ChildContent { get; set; } + + private List> Items = new List>(); + + private CustomSelectCondition Condition { get; set; } + + private object FilterValue { get; set; } + + protected override void OnInitialized() + { + Column.FilterControl = this; + + if (Column.Filter?.Body is BinaryExpression binaryExpression) + { + if (binaryExpression.NodeType == ExpressionType.AndAlso) + { + switch (binaryExpression.Right.NodeType) + { + case ExpressionType.Equal: + Condition = CustomSelectCondition.IsEqualTo; + break; + case ExpressionType.NotEqual: + Condition = CustomSelectCondition.IsNotEqualTo; + break; + } + } + else + { + if (binaryExpression.NodeType == ExpressionType.Equal) + { + Condition = CustomSelectCondition.IsNull; + } + else if (binaryExpression.NodeType == ExpressionType.NotEqual) + { + Condition = CustomSelectCondition.IsNotNull; + } + } + + if (binaryExpression.Right is BinaryExpression binaryExpression2 + && binaryExpression2.Right is ConstantExpression constantExpression) + { + FilterValue = constantExpression.Value; + } + } + } + + public Expression> GetFilter() + { + return Condition switch + { + CustomSelectCondition.IsEqualTo => + Expression.Lambda>( + Expression.AndAlso( + Expression.NotEqual(Column.Field.Body, Expression.Constant(null)), + Expression.Equal( + Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()), + Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))), + Column.Field.Parameters), + + CustomSelectCondition.IsNotEqualTo => Expression.Lambda>( + Expression.AndAlso( + Expression.NotEqual(Column.Field.Body, Expression.Constant(null)), + Expression.NotEqual( + Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()), + Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))), + Column.Field.Parameters), + + CustomSelectCondition.IsNull => + Expression.Lambda>( + Expression.Equal(Column.Field.Body, Expression.Constant(null)), + Column.Field.Parameters), + + CustomSelectCondition.IsNotNull => + Expression.Lambda>( + Expression.NotEqual(Column.Field.Body, Expression.Constant(null)), + Column.Field.Parameters), + + _ => throw new ArgumentException(Condition + " is not defined!"), + }; + } + + public void AddSelect(string key, object value) + { + Items.Add(new KeyValuePair(key, value)); + StateHasChanged(); + } + + public enum CustomSelectCondition + { + [Description("Is Equal To")] + IsEqualTo, + + [Description("Is Not Equal To")] + IsNotEqualTo, + + [Description("Is null")] + IsNull, + + [Description("Is not null")] + IsNotNull + } + } +} diff --git a/src/BlazorTable/Filters/EnumFilter.razor.cs b/src/BlazorTable/Filters/EnumFilter.razor.cs index f846d1e5..d2d23618 100644 --- a/src/BlazorTable/Filters/EnumFilter.razor.cs +++ b/src/BlazorTable/Filters/EnumFilter.razor.cs @@ -21,8 +21,6 @@ protected override void OnInitialized() { Column.FilterControl = this; - FilterValue = Enum.GetValues(Column.Type.GetNonNullableType()).GetValue(0); - if (Column.Filter?.Body is BinaryExpression binaryExpression) { if (binaryExpression.NodeType == ExpressionType.AndAlso) diff --git a/src/BlazorTable/Interfaces/ICustomSelect.cs b/src/BlazorTable/Interfaces/ICustomSelect.cs new file mode 100644 index 00000000..e1977af5 --- /dev/null +++ b/src/BlazorTable/Interfaces/ICustomSelect.cs @@ -0,0 +1,7 @@ +namespace BlazorTable +{ + public interface ICustomSelect + { + public void AddSelect(string key, object value); + } +} \ No newline at end of file