Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,9 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu
/// <inheritdoc/>
/// </summary>
public bool IsMarkupString { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool? IgnoreWhenExport { get; set; }
}
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Components/Table/ITableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ namespace BootstrapBlazor.Components;
/// </summary>
public interface ITableColumn : IEditorItem
{
/// <summary>
/// Gets or sets whether the current item is ignored when export operation. Default is false.
/// </summary>
bool? IgnoreWhenExport { get; set; }

/// <summary>
/// Gets or sets whether sorting is allowed. Default is null.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/BootstrapBlazor/Components/Table/InternalTableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,9 @@ class InternalTableColumn(string fieldName, Type fieldType, string? fieldText =
/// <inheritdoc/>
/// </summary>
public Func<ITableColumn, string?, SearchFilterAction>? CustomSearch { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
public bool? IgnoreWhenExport { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ public IEnumerable<ITableColumn> 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;
Expand Down
6 changes: 6 additions & 0 deletions src/BootstrapBlazor/Components/Table/TableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
[Parameter]
public Expression<Func<TType>>? FieldExpression { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
[Parameter]
public bool? IgnoreWhenExport { get; set; }

/// <summary>
/// <inheritdoc/>
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions src/BootstrapBlazor/Extensions/ITableColumnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
Expand Down Expand Up @@ -343,6 +344,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;
Expand Down
4 changes: 3 additions & 1 deletion test/UnitTest/Attributes/AutoGenerateClassTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions test/UnitTest/Components/InternalTableColumnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
31 changes: 31 additions & 0 deletions test/UnitTest/Components/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8208,6 +8208,37 @@ public void IsMarkupString_Ok()
Assert.Equal("<div class=\"table-cell\">&lt;div&gt;Address - Test&lt;/div&gt;</div>", cells[1].InnerHtml);
}

[Fact]
public void IgnoreWhenExport_Ok()
{
var items = new Foo[] { new() { Name = "Name", Address = "Address" } };
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Table<Foo>>(pb =>
{
pb.Add(a => a.RenderMode, TableRenderMode.Table);
pb.Add(a => a.Items, items);
pb.Add(a => a.TableColumns, foo => builder =>
{
builder.OpenComponent<TableColumn<Foo, string>>(0);
builder.AddAttribute(1, "Field", "Name");
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
builder.CloseComponent();

builder.OpenComponent<TableColumn<Foo, string>>(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<Table<Foo>>();
var columns = table.Instance.GetVisibleColumns();
Assert.Single(columns);
}

[Fact]
public void OnSelectedRows_Ok()
{
Expand Down
3 changes: 2 additions & 1 deletion test/UnitTest/Utils/UtilityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,13 @@ public void GenerateTableColumns_Ok()
{
var cols = Utility.GetTableColumns<Cat>(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]
Expand Down