AdminTable Component

Overview

AdminTable is the core universal data table component in the system, extended from BootstrapBlazor's Table<TItem> component. It encapsulates a full set of features including CRUD operations, pagination and sorting, search and filtering, import/export, data permissions, and tree display. Almost all admin management pages in the system use this component.

Features

  • Supports CRUD operations with automatic pagination and sorting
  • Supports Excel import/export with template download
  • Supports tree table display (IsTree) with automatic parent-child hierarchy handling
  • Built-in data permission control (UseDataPermission) for automatic filtering by user's department
  • Supports simple search and advanced search (multi-condition combined queries)
  • Provides lifecycle events such as before query, before/after save, before/after delete, and before/after import
  • Automatically controls button visibility based on button permissions ([AdminButton])
  • Supports custom edit dialog templates (EditTemplate)

Parameters

Type Parameters

Parameter Description
TItem Entity type, must implement IEntity<TKey> interface
TKey Primary key type

Property Parameters

Parameter Type Description
IsTree bool Whether it is a tree table
IsMultipleSelect bool Whether to enable multi-select
ShowSearch bool Whether to show the search box
ShowAdvancedSearch bool Whether to show the advanced search button
ShowExtendButtons bool Whether to show extension buttons
ShowImportButton bool Whether to show the import button
ShowExportButton bool Whether to show the export button
UseDataPermission bool Whether to enable data permission filtering
EnableDraft bool Whether to enable draft auto-save to prevent data loss from accidental page closure
EnableSaveWithoutClose bool Whether to enable save without closing
DraftAutoSaveInterval int Draft auto-save interval (seconds), default 30 seconds
EditDialogSize Size Edit dialog size
IgnoreSearchColumns Expression Specify columns to ignore in search
GetParentId Func Parent ID delegate for tree table
OnBeforeQuery EventCallback Before query event, for appending Includes, Where, etc.
OnBeforeSaveAsync EventCallback Before save event, for data validation or preprocessing
OnFinishSaveAsync EventCallback After save event, for follow-up processing (e.g., creating tenant admin)
OnBeforeDeleteAsync EventCallback Before delete event, for cascade loading or cancellation
OnBeforeImportAsync EventCallback Before import event, for custom import logic

Usage Examples

Basic Usage

<AdminTable TItem="SysUser" TKey="long"
    ShowSearch ShowAdvancedSearch ShowExtendButtons
    OnBeforeQuery="OnBeforeQuery"
    OnBeforeSaveAsync="OnBeforeSaveAsync"
    OnBeforeDeleteAsync="OnBeforeDeleteAsync">
    <TableColumns>
        <TableColumn @bind-Field="context.Username" Text="Username" />
        <TableColumn @bind-Field="context.Nickname" Text="Nickname" />
        <TableColumn @bind-Field="context.IsEnabled" Text="Status" />
    </TableColumns>
</AdminTable>

Tree Table

<AdminTable TItem="SysMenu" TKey="long" IsTree IsMultipleSelect
    OnBeforeQuery="OnBeforeQuery" ... />

Appending Include Before Query

private void OnBeforeQuery(AdminQueryEventArgs<SysUser> e)
{
    e.Select.IncludeMany(a => a.Roles).Include(a => a.Org);
}

Validation Before Save

private async Task OnBeforeSaveAsync(AdminSaveEventArgs<SysUser> e)
{
    if (await _repo.Select.Where(a => a.Username == e.Item.Username).AnyAsync())
    {
        await SwalService.Error("Username already exists");
        e.Cancel = true;
    }
}

Notes

  1. When using data permissions, the entity must implement the IDataPermission interface
  2. The default import file size limit is 5MB
  3. Tree tables require setting the GetParentId parameter