Skip to content

Commit

Permalink
feat(TableTemplateColumn): add TableTemplateColumn component (#3879)
Browse files Browse the repository at this point in the history
* feat: 增加 TableTemplateColumn 组件

* feat: 增加可为空约束

* refactor: 支持 TableTemplateColumn 组件

* refactor: 优化代码

* chore: bump vesion 8.7.3-beta05

* refactor: 格式化代码
  • Loading branch information
ArgoZhang committed Jul 19, 2024
1 parent 8ce03fe commit f731547
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor.Server/Components/Samples/Tabs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<p>@Localizer["TabsTips4"]</p>
</Tips>

<p>
<p class="mb-3">
<b>@Localizer["TabsInfoTitle"]</b>
</p>

Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.7.3-beta04</Version>
<Version>8.7.3-beta05</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
15 changes: 11 additions & 4 deletions src/BootstrapBlazor/Components/Table/TableColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
}
}
#elif NET6_0_OR_GREATER
public RenderFragment<TableColumnContext<TItem, TType>>? Template { get; set; }
public RenderFragment<TableColumnContext<TItem, TType?>>? Template { get; set; }

/// <summary>
/// 内部使用负责把 object 类型的绑定数据值转化为泛型数据传递给前端
Expand All @@ -305,9 +305,16 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
get => Template == null ? null : new RenderFragment<object>(context => builder =>
{
// 此处 context 为行数据
var fieldName = GetFieldName();
var value = Utility.GetPropertyValue<object, TType>(context, fieldName);
builder.AddContent(0, Template.Invoke(new TableColumnContext<TItem, TType>((TItem)context, value)));
if (this is TableTemplateColumn<TItem> col)
{
builder.AddContent(0, Template.Invoke(new TableColumnContext<TItem, TType?>((TItem)context, default)));
}
else
{
var fieldName = GetFieldName();
var value = Utility.GetPropertyValue<object, TType?>(context, fieldName);
builder.AddContent(0, Template.Invoke(new TableColumnContext<TItem, TType?>((TItem)context, value)));
}
});
set
{
Expand Down
17 changes: 17 additions & 0 deletions src/BootstrapBlazor/Components/Table/TableTemplateColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

using Microsoft.AspNetCore.Components.Forms;
using System.Linq.Expressions;

namespace BootstrapBlazor.Components;

/// <summary>
/// TableTemplateColumn 表格模板列
/// </summary>
/// <remarks>不需要绑定模型属性</remarks>
public class TableTemplateColumn<TItem> : TableColumn<TItem, object>
{

}

0 comments on commit f731547

Please sign in to comment.