From 26d2878e6bdb5ec902996fad27cdd2edc06ff7b7 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 10 May 2025 10:28:40 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20TableExportAtt?= =?UTF-8?q?ribute=20=E6=A0=87=E7=AD=BE=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attributes/TableExportAttribute.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/BootstrapBlazor/Attributes/TableExportAttribute.cs diff --git a/src/BootstrapBlazor/Attributes/TableExportAttribute.cs b/src/BootstrapBlazor/Attributes/TableExportAttribute.cs new file mode 100644 index 00000000000..bd0bb883107 --- /dev/null +++ b/src/BootstrapBlazor/Attributes/TableExportAttribute.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +namespace BootstrapBlazor.Components; + +/// +/// TableExport attribute class +/// +[AttributeUsage(AttributeTargets.Property)] +public class TableExportAttribute : Attribute +{ + /// + /// Gets or sets whether the current column is ignored when export operation. Default is false. When set to true, the UI will not generate this column. + /// + public bool Ignore { get; set; } +} From e6ac53ad8fc17545fab19e71358504df0e65b893 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 10 May 2025 10:29:00 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20IgnoreWhenExpo?= =?UTF-8?q?rt=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Table/ITableColumn.cs | 5 +++++ src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs | 2 +- src/BootstrapBlazor/Components/Table/TableColumn.cs | 5 +++++ src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/BootstrapBlazor/Components/Table/ITableColumn.cs b/src/BootstrapBlazor/Components/Table/ITableColumn.cs index a91528f52fd..ac004056c6b 100644 --- a/src/BootstrapBlazor/Components/Table/ITableColumn.cs +++ b/src/BootstrapBlazor/Components/Table/ITableColumn.cs @@ -10,6 +10,11 @@ namespace BootstrapBlazor.Components; /// public interface ITableColumn : IEditorItem { + /// + /// Gets or sets whether the current item is ignored when export operation. Default is false. + /// + bool? IgnoreWhenExport { get; set; } + /// /// Gets or sets whether sorting is allowed. Default is null. /// diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs index 968f51cbd38..dca4728d55b 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs @@ -470,7 +470,7 @@ public IEnumerable GetVisibleColumns() { // 不可见列 var items = VisibleColumns.Where(i => i.Visible); - return Columns.Where(i => !i.GetIgnore() && items.Any(v => v.Name == i.GetFieldName()) && ScreenSize >= i.ShownWithBreakPoint); + return Columns.Where(i => !i.GetIgnoreExport() && !i.GetIgnore() && items.Any(v => v.Name == i.GetFieldName()) && ScreenSize >= i.ShownWithBreakPoint); } private bool GetColumnsListState(ColumnVisibleItem item) => VisibleColumns.Find(i => i.Name == item.Name) is { Visible: true } && VisibleColumns.Where(i => i.Visible).DistinctBy(i => i.Name).Count(i => i.Visible) == 1; diff --git a/src/BootstrapBlazor/Components/Table/TableColumn.cs b/src/BootstrapBlazor/Components/Table/TableColumn.cs index 91f9695ed10..82fde87b53a 100644 --- a/src/BootstrapBlazor/Components/Table/TableColumn.cs +++ b/src/BootstrapBlazor/Components/Table/TableColumn.cs @@ -51,6 +51,11 @@ public class TableColumn : BootstrapComponentBase, ITableColumn [Parameter] public Expression>? FieldExpression { get; set; } + /// + /// + /// + public bool? IgnoreWhenExport { get; set; } + /// /// /// diff --git a/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs b/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs index e10c6aaa341..8611bde3d8e 100644 --- a/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs +++ b/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs @@ -343,6 +343,8 @@ private static RenderFragment RenderContent(this ITableColumn col, string? text) internal static bool GetVisible(this ITableColumn col) => col.Visible ?? true; + internal static bool GetIgnoreExport(this ITableColumn col) => col.IgnoreWhenExport ?? false; + internal static bool GetShowCopyColumn(this ITableColumn col) => col.ShowCopyColumn ?? false; internal static bool GetShowTips(this ITableColumn col) => col.ShowTips ?? false; From fea0a3b27cefce15247ec1eb5ab57963794a9ccf Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 10 May 2025 11:03:40 +0800 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20IgnoreWhenExpo?= =?UTF-8?q?rt=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attributes/AutoGenerateColumnAttribute.cs | 5 +++++ src/BootstrapBlazor/Components/Table/InternalTableColumn.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs b/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs index e8a5e8b216d..6e8ff39beca 100644 --- a/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs +++ b/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs @@ -315,4 +315,9 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu /// /// public bool IsMarkupString { get; set; } + + /// + /// + /// + public bool? IgnoreWhenExport { get; set; } } diff --git a/src/BootstrapBlazor/Components/Table/InternalTableColumn.cs b/src/BootstrapBlazor/Components/Table/InternalTableColumn.cs index 12586f2e719..59a7d6de30c 100644 --- a/src/BootstrapBlazor/Components/Table/InternalTableColumn.cs +++ b/src/BootstrapBlazor/Components/Table/InternalTableColumn.cs @@ -322,4 +322,9 @@ class InternalTableColumn(string fieldName, Type fieldType, string? fieldText = /// /// public Func? CustomSearch { get; set; } + + /// + /// + /// + public bool? IgnoreWhenExport { get; set; } } From 2aab53495aa981919f8b6652d2dccd64717d692e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 10 May 2025 12:02:00 +0800 Subject: [PATCH 4/7] =?UTF-8?q?revert:=20=E5=88=A0=E9=99=A4=20TableExportA?= =?UTF-8?q?ttribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attributes/TableExportAttribute.cs | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 src/BootstrapBlazor/Attributes/TableExportAttribute.cs diff --git a/src/BootstrapBlazor/Attributes/TableExportAttribute.cs b/src/BootstrapBlazor/Attributes/TableExportAttribute.cs deleted file mode 100644 index bd0bb883107..00000000000 --- a/src/BootstrapBlazor/Attributes/TableExportAttribute.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the Apache 2.0 License -// See the LICENSE file in the project root for more information. -// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone - -namespace BootstrapBlazor.Components; - -/// -/// TableExport attribute class -/// -[AttributeUsage(AttributeTargets.Property)] -public class TableExportAttribute : Attribute -{ - /// - /// Gets or sets whether the current column is ignored when export operation. Default is false. When set to true, the UI will not generate this column. - /// - public bool Ignore { get; set; } -} From fbf736fb0a79e418a279a19887f3c27bb161cdbf Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 10 May 2025 12:02:09 +0800 Subject: [PATCH 5/7] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Components/Table/TableColumn.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BootstrapBlazor/Components/Table/TableColumn.cs b/src/BootstrapBlazor/Components/Table/TableColumn.cs index 82fde87b53a..af50f4ecf0a 100644 --- a/src/BootstrapBlazor/Components/Table/TableColumn.cs +++ b/src/BootstrapBlazor/Components/Table/TableColumn.cs @@ -54,6 +54,7 @@ public class TableColumn : BootstrapComponentBase, ITableColumn /// /// /// + [Parameter] public bool? IgnoreWhenExport { get; set; } /// From c2e37898a1c0d2163d3781d407f60955c614049f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 10 May 2025 12:02:26 +0800 Subject: [PATCH 6/7] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=BB=A7=E6=89=BF=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs b/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs index 8611bde3d8e..86631ffefb2 100644 --- a/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs +++ b/src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs @@ -111,6 +111,7 @@ private static void CopyValue(this ITableColumn col, ITableColumn dest) if (col.ToolboxTemplate != null) dest.ToolboxTemplate = col.ToolboxTemplate; if (col.IsRequiredWhenAdd.HasValue) dest.IsRequiredWhenAdd = col.IsRequiredWhenAdd; if (col.IsRequiredWhenEdit.HasValue) dest.IsRequiredWhenEdit = col.IsRequiredWhenEdit; + if (col.IgnoreWhenExport.HasValue) dest.IgnoreWhenExport = col.IgnoreWhenExport; } /// From 38cf1e192173238761b456a5f503c6b44df3b1d4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 10 May 2025 12:02:39 +0800 Subject: [PATCH 7/7] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attributes/AutoGenerateClassTest.cs | 4 ++- .../Components/InternalTableColumnTest.cs | 1 + test/UnitTest/Components/TableTest.cs | 31 +++++++++++++++++++ test/UnitTest/Utils/UtilityTest.cs | 3 +- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/test/UnitTest/Attributes/AutoGenerateClassTest.cs b/test/UnitTest/Attributes/AutoGenerateClassTest.cs index 575853f3252..fd005c21d55 100644 --- a/test/UnitTest/Attributes/AutoGenerateClassTest.cs +++ b/test/UnitTest/Attributes/AutoGenerateClassTest.cs @@ -71,7 +71,8 @@ public void AutoGenerateColumn_Ok() HeaderTextWrap = true, IsMarkupString = true, - RequiredErrorMessage = "test" + RequiredErrorMessage = "test", + IgnoreWhenExport = true }; Assert.Equal(1, attr.Order); Assert.True(attr.Ignore); @@ -105,6 +106,7 @@ public void AutoGenerateColumn_Ok() Assert.True(attr.HeaderTextEllipsis); Assert.Equal("test header tooltip", attr.HeaderTextTooltip); Assert.True(attr.IsMarkupString); + Assert.True(attr.IgnoreWhenExport); var attrInterface = (ITableColumn)attr; attrInterface.ShowLabelTooltip = true; diff --git a/test/UnitTest/Components/InternalTableColumnTest.cs b/test/UnitTest/Components/InternalTableColumnTest.cs index 87a0af94e69..116bf2c17d0 100644 --- a/test/UnitTest/Components/InternalTableColumnTest.cs +++ b/test/UnitTest/Components/InternalTableColumnTest.cs @@ -86,6 +86,7 @@ public void InternalTableColumn_Ok() SetValue("IsRequiredWhenAdd", true); SetValue("IsRequiredWhenEdit", true); SetValue("LookupService", null); + SetValue("IgnoreWhenExport", true); void SetValue(string propertyName, object? val) => type!.GetProperty(propertyName)!.SetValue(instance, val); } diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index 15020509840..17e862a42bd 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -8208,6 +8208,37 @@ public void IsMarkupString_Ok() Assert.Equal("
<div>Address - Test</div>
", cells[1].InnerHtml); } + [Fact] + public void IgnoreWhenExport_Ok() + { + var items = new Foo[] { new() { Name = "Name", Address = "Address" } }; + var cut = Context.RenderComponent(pb => + { + pb.AddChildContent>(pb => + { + pb.Add(a => a.RenderMode, TableRenderMode.Table); + pb.Add(a => a.Items, items); + pb.Add(a => a.TableColumns, foo => builder => + { + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Name"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string))); + builder.CloseComponent(); + + builder.OpenComponent>(0); + builder.AddAttribute(1, "Field", "Address"); + builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Address", typeof(string))); + builder.AddAttribute(3, "IgnoreWhenExport", true); + builder.CloseComponent(); + }); + }); + }); + + var table = cut.FindComponent>(); + var columns = table.Instance.GetVisibleColumns(); + Assert.Single(columns); + } + [Fact] public void OnSelectedRows_Ok() { diff --git a/test/UnitTest/Utils/UtilityTest.cs b/test/UnitTest/Utils/UtilityTest.cs index bb3340527e6..dd9a83a7ef9 100644 --- a/test/UnitTest/Utils/UtilityTest.cs +++ b/test/UnitTest/Utils/UtilityTest.cs @@ -581,12 +581,13 @@ public void GenerateTableColumns_Ok() { var cols = Utility.GetTableColumns(new InternalTableColumn[] { - new(nameof(Cat.Name), typeof(string)) { Text = "test-Name", LookupServiceData = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false } + new(nameof(Cat.Name), typeof(string)) { Text = "test-Name", LookupServiceData = true, IsVisibleWhenAdd = false, IsVisibleWhenEdit = false, IgnoreWhenExport = true } }); Assert.Equal(2, cols.Count()); Assert.Equal(true, cols.First().LookupServiceData); Assert.False(cols.First().IsVisibleWhenAdd); Assert.False(cols.First().IsVisibleWhenEdit); + Assert.True(cols.First().IgnoreWhenExport); } [Fact]