AdminSelectTable 组件
组件概述
AdminSelectTable 是一个基于泛型的表格选择组件,继承自 ValidateBase<TItem>
,主要用于从表格数据中选择条目。
泛型参数
@typeparam TItem where TItem : class, IEntity<long>, new()
TItem
必须实现IEntity<long>
接口TItem
必须有无参构造函数
主要功能
- 表格形式展示可选择的数据
- 支持分页查询
- 支持数据权限过滤
- 提供选择项变更事件
属性说明
属性 | 类型 | 说明 |
---|---|---|
TableColumns | RenderFragment<TItem> |
表格列定义模板 |
GetText | Func<TItem, string> |
获取显示文本的委托 |
UseDataPermission | bool |
是否启用数据权限过滤 |
Value | TItem |
当前选中的条目 |
ValueId | long? |
当前选中条目的ID |
方法说明
OnQueryAsync
private async Task<QueryData<TItem>> OnQueryAsync(QueryPageOptions options)
- 执行分页查询
- 自动应用数据权限过滤(当
UseDataPermission
为 true 时)
OnSelectedItemChangedInternal
private async Task OnSelectedItemChangedInternal(TItem? item)
- 处理选择项变更事件
- 触发
ValueChanged
回调
使用示例
<TableColumn @bind-Field="context.SubjectId" Text="SubjectId" Filterable="true">
<Template Context="v">@v.Row.Article?.Title</Template>
<EditTemplate Context="v">
<div class="col-12">
<AdminSelectTable TItem="Article" GetText="x => x.Title" @bind-Value="v.Article" @bind-ValueId="v.SubjectId">
<TableColumns Context="sv">
<TableColumn @bind-Field="sv.Title" Filterable="true" />
</TableColumns>
</AdminSelectTable>
</div>
</EditTemplate>
</TableColumn>
注意事项
- 实体类必须实现
IEntity<long>
接口 - 如需使用数据权限,实体必须同时实现
IDataPermission
和IEntityCreated
接口