feat: 表头支持自动获取显示名称
This commit is contained in:
parent
f383b62864
commit
8fae244170
|
@ -40,7 +40,7 @@ namespace Bootstrap.Admin.Components
|
|||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public RenderFragment? TableHeader { get; set; }
|
||||
public RenderFragment<TItem>? TableHeader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
using Bootstrap.Admin.Extensions;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.AspNetCore.Components.Rendering;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Bootstrap.Admin.Components
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class LgbTableHeader<TItem> : ComponentBase
|
||||
{
|
||||
#nullable disable
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter] public TItem Value { get; set; }
|
||||
#nullable restore
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter] public EventCallback<TItem> ValueChanged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter] public Expression<Func<TItem>>? ValueExpression { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
var filed = FieldIdentifier.Create(ValueExpression);
|
||||
var text = filed.GetDisplayName();
|
||||
builder.OpenElement(0, "th");
|
||||
builder.AddContent(1, text);
|
||||
builder.CloseElement();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ namespace Bootstrap.Admin.Components
|
|||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public RenderFragment? TableHeader { get; set; }
|
||||
public RenderFragment<TItem>? TableHeader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -224,7 +224,6 @@ namespace Bootstrap.Admin.Components
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
protected CheckBoxState CheckState(TItem item)
|
||||
{
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
<LgbInputText @bind-Value="@context.Name" maxlength="50" />
|
||||
</QueryBody>
|
||||
<TableHeader>
|
||||
<th>字典标签</th>
|
||||
<th>字典名称</th>
|
||||
<th>字典代码</th>
|
||||
<th>字典类型</th>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Category"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Name"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="string" @bind-Value="@context.Code"></LgbTableHeader>
|
||||
<LgbTableHeader TItem="int" @bind-Value="@context.Define"></LgbTableHeader>
|
||||
</TableHeader>
|
||||
<RowTemplate>
|
||||
<td>@context.Category</td>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<div class="card-body">
|
||||
<Table @ref="Table" Id="@Id" TItem="TItem" OnQuery="QueryData" OnAdd="OnAdd" OnDelete="OnDelete" OnSave="OnSave">
|
||||
<TableHeader>
|
||||
@TableHeader
|
||||
@TableHeader?.Invoke(context)
|
||||
</TableHeader>
|
||||
<RowTemplate>
|
||||
@RowTemplate?.Invoke(context)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
{
|
||||
<th class="table-col-checkbox"><Checkbox TItem="TItem" SetCheckCallback="CheckState" ToggleCallback="ToggleCheck"></Checkbox></th>
|
||||
}
|
||||
@TableHeader
|
||||
@TableHeader?.Invoke(EditModel)
|
||||
@if (ShowButtons)
|
||||
{
|
||||
<th>@ButtonTemplateHeaderText</th>
|
||||
|
|
Loading…
Reference in New Issue