feat: 表头支持自动获取显示名称
This commit is contained in:
parent
f383b62864
commit
8fae244170
|
@ -40,7 +40,7 @@ namespace Bootstrap.Admin.Components
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public RenderFragment? TableHeader { get; set; }
|
public RenderFragment<TItem>? TableHeader { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public RenderFragment? TableHeader { get; set; }
|
public RenderFragment<TItem>? TableHeader { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
|
@ -224,7 +224,6 @@ namespace Bootstrap.Admin.Components
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected CheckBoxState CheckState(TItem item)
|
protected CheckBoxState CheckState(TItem item)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
<LgbInputText @bind-Value="@context.Name" maxlength="50" />
|
<LgbInputText @bind-Value="@context.Name" maxlength="50" />
|
||||||
</QueryBody>
|
</QueryBody>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<th>字典标签</th>
|
<LgbTableHeader TItem="string" @bind-Value="@context.Category"></LgbTableHeader>
|
||||||
<th>字典名称</th>
|
<LgbTableHeader TItem="string" @bind-Value="@context.Name"></LgbTableHeader>
|
||||||
<th>字典代码</th>
|
<LgbTableHeader TItem="string" @bind-Value="@context.Code"></LgbTableHeader>
|
||||||
<th>字典类型</th>
|
<LgbTableHeader TItem="int" @bind-Value="@context.Define"></LgbTableHeader>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<RowTemplate>
|
<RowTemplate>
|
||||||
<td>@context.Category</td>
|
<td>@context.Category</td>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<Table @ref="Table" Id="@Id" TItem="TItem" OnQuery="QueryData" OnAdd="OnAdd" OnDelete="OnDelete" OnSave="OnSave">
|
<Table @ref="Table" Id="@Id" TItem="TItem" OnQuery="QueryData" OnAdd="OnAdd" OnDelete="OnDelete" OnSave="OnSave">
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
@TableHeader
|
@TableHeader?.Invoke(context)
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<RowTemplate>
|
<RowTemplate>
|
||||||
@RowTemplate?.Invoke(context)
|
@RowTemplate?.Invoke(context)
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
{
|
{
|
||||||
<th class="table-col-checkbox"><Checkbox TItem="TItem" SetCheckCallback="CheckState" ToggleCallback="ToggleCheck"></Checkbox></th>
|
<th class="table-col-checkbox"><Checkbox TItem="TItem" SetCheckCallback="CheckState" ToggleCallback="ToggleCheck"></Checkbox></th>
|
||||||
}
|
}
|
||||||
@TableHeader
|
@TableHeader?.Invoke(EditModel)
|
||||||
@if (ShowButtons)
|
@if (ShowButtons)
|
||||||
{
|
{
|
||||||
<th>@ButtonTemplateHeaderText</th>
|
<th>@ButtonTemplateHeaderText</th>
|
||||||
|
|
Loading…
Reference in New Issue