跳转到内容

SusDataTable

SusDataTable

带工具栏、类型化单元格、排序 / 搜索 / 分页的数据表格 — 由 SusTableController 驱动。

SusKit · 数据(商业)

在 Playground 中打开

SusKit · Data

属性

名称类型默认值
ControllerProp<SusTableController>new()v-model
ShowToolbarProp<bool>truev-model
DensityProp<string>"default"v-model
VariantProp<string>"elevated"v-model
HoverProp<bool>truev-model

插槽

名称
toolbar

事件

没有公开事件。

样式钩子

USS 类契约 — 无需改 C# 即可覆盖外观。状态通过这些类切换:

  • sus-data-table__action-btn
  • sus-data-table__cell
  • sus-data-table__cell--actions
  • sus-data-table__cell--align-center
  • sus-data-table__cell--align-end
  • sus-data-table__cell--description
  • sus-data-table__cell--number
  • sus-data-table__cell--select
  • sus-data-table__cell--toggle
  • sus-data-table__cell-wrap
  • sus-data-table__empty
  • sus-data-table__empty-text
  • sus-data-table__footer
  • sus-data-table__footer-btn
  • sus-data-table__footer-info
  • sus-data-table__footer-left
  • sus-data-table__footer-right
  • sus-data-table__footer-select
  • sus-data-table__header-cell
  • sus-data-table__header-cell--sort-wired
  • sus-data-table__header-cell--sortable
  • sus-data-table__header-title
  • sus-data-table__header-title--align-center
  • sus-data-table__header-title--align-end
  • sus-data-table__header-title--sortable
  • sus-data-table__host
  • sus-data-table__loading-bar
  • sus-data-table__loading-overlay
  • sus-data-table__search
  • sus-data-table__sort-btn
  • sus-data-table__sort-btn--active
  • sus-data-table__toolbar
  • sus-data-table__toolbar-actions
  • sus-data-table__view
  • sus-data-table--density-comfortable
  • sus-data-table--density-compact
  • sus-data-table--hover
  • sus-data-table--variant-flat
  • sus-data-table--variant-outlined
  • sus-select
  • sus-select__details
  • sus-select__field
  • sus-select__value
  • sus-slot
  • sus-table__action-btn
  • sus-table__cell--toggle
  • unity-collection-view__item
  • unity-collection-view__item--selected
  • unity-list-view__item
  • unity-list-view__item--alternated
  • unity-list-view__item--selected
  • unity-multi-column-header
  • unity-multi-column-header__column
  • unity-multi-column-header__column__sort-indicator
  • unity-multi-column-header__column-sorting
  • unity-multi-column-header__column-sorting-indicator

用法

列和行定义在控制器上(SetColumns / SetItems)。可选的 ApplyKindDefaults 应用一个 SusTableKind 预设。

csharp
var ctrl = new SusTableController();
ctrl.ApplyKindDefaults(SusTableKind.MainList);
ctrl.SetColumns(new List<ColumnDef>
{
    new() { Key = "Name", Title = "Name", MinWidth = 140f, Sortable = true, Searchable = true },
    new() { Key = "Role", Title = "Role", Width = 100f, Sortable = true },
    new() { Key = "Level", Title = "Lvl", Width = 72f, Align = "end",
            CellType = SusCellType.Number, Sortable = true },
});
ctrl.SetItems(new List<object>
{
    new Dictionary<string, object> { ["Name"] = "Aria", ["Role"] = "Tank", ["Level"] = 12 },
    new Dictionary<string, object> { ["Name"] = "Borin", ["Role"] = "DPS", ["Level"] = 9 },
});
ctrl.SetItemsPerPage(5);

var table = new SusDataTable();
table.Controller.Value = ctrl;
table.ShowToolbar.Value = true;
table.Density.Value = "default";
table.Variant.Value = "elevated";
table.Hover.Value = true;
xml
<template>
  <sus:SusDataTable :Controller="TableCtrl.Value"
                    :ShowToolbar="ShowToolbar.Value"
                    :Density="Density.Value"
                    :Variant="Variant.Value"
                    :Hover="Hover.Value">
    <template #toolbar>
      <!-- Optional actions next to global search -->
    </template>
  </sus:SusDataTable>
</template>

<script>
public Prop<SusTableController> TableCtrl = new(new());
public Prop<bool> ShowToolbar = new(true);
public Prop<string> Density = new("default");
public Prop<string> Variant = new("elevated");
public Prop<bool> Hover = new(true);
// Populate TableCtrl columns/items in code (see above).
</script>
Prop作用
ControllerSusTableController — 列、条目、排序、搜索、分页
ShowToolbar全局搜索 + toolbar 插槽
Densitydefault · compact · comfortable
Variantelevated · flat · outlined
Hover行悬停高亮

说明

  • 需要工具栏、kind 预设或类型化单元格(SusCellType:text · number · icon · image · toggle · badge · progress · description · actions)时,优先用 SusDataTable 而不是 SusTable
  • SusTableKindMainList · Picker · ActionList · ReadOnly · Dev — 通过 ApplyKindDefaults 应用。
  • 行操作 / 选择 / 加载状态定义在控制器上(OptionsRowActionRequestedLoading 等)。
  • Items 显示内置空状态;设置 Loading 显示遮罩加载条。