跳转到内容

SusDataTable ​

SusDataTable

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

包

SusKit · 数据(商业)

在 Playground 中打开

SusKit · Data

属性

名称类型默认值
ControllerProp<SusTableController>new SusTableController()v-model
ShowToolbarProp<bool>truev-model
DensityProp<string>"default"v-model
VariantProp<string>"elevated"v-model
HoverProp<bool>truev-model
SearchPlaceholderProp<string>"Search..."v-model
EmptyTextProp<string>"No data available"v-model
RowsPerPageLabelProp<string>"Rows per page:"v-model
RowsPerPageAutoLabelProp<string>"Rows per page: auto"v-model
AllRowsLabelProp<string>"All"v-model

插槽

名称
toolbar

事件

没有公开事件。

样式钩子 ​

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

  • keyboard-focus
  • sus-data-table
  • 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--fixed-width
  • sus-data-table__cell--select
  • sus-data-table__cell--toggle
  • sus-data-table__cell-wrap
  • sus-data-table__empty
  • sus-data-table__empty-frame
  • 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__host--fixed-height
  • sus-data-table__loading-bar
  • sus-data-table__loading-overlay
  • sus-data-table__radio
  • sus-data-table__radio--disabled
  • sus-data-table__radio--on
  • sus-data-table__radio-dot
  • sus-data-table__row-marker
  • sus-data-table__row-marker--on
  • sus-data-table__row-marker--pulse
  • sus-data-table__search
  • sus-data-table__skeleton
  • sus-data-table__skeleton-bar
  • sus-data-table__skeleton-bar--alt
  • sus-data-table__skeleton-row
  • 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-healthbar
  • sus-hidden
  • sus-select
  • sus-select__details
  • sus-select__field
  • sus-select__value
  • sus-slot
  • sus-table__action-btn
  • sus-table__cell--boxed
  • sus-table__cell--custom
  • sus-table__cell--media
  • sus-table__cell--number
  • sus-table__cell--progress
  • sus-table__cell--segments
  • sus-table__cell--toggle
  • sus-table__cell--two-line
  • sus-table__cell-sub
  • sus-table__cell-title
  • sus-table__segment
  • sus-table__segment--on
  • sus-table__segments
  • sus-table__segments--full
  • sus-table__segments-count
  • sus-textfield
  • 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
  • unity-multi-column-view__header-container

用法 ​

列和行定义在控制器上(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行悬停高亮

双行单元格 ​

SusHeaders.TwoLine(key, subKey, title) 在一个单元格中放入两个值:key 的值作为标题,subKey 的值作为标题下方较淡的第二行(SusCellType.TwoLine)。适用于名称旁需要附带服务器、地区或副标题的情况。

csharp
ctrl.SetColumns(new List<ColumnDef>
{
    SusHeaders.TwoLine("Name", "World", "Player"),
    SusHeaders.Number("Rating"),
});
ctrl.SetItems(new List<object>
{
    new Dictionary<string, object> { ["Name"] = "Aria", ["World"] = "North Reach", ["Rating"] = 1840 },
    new Dictionary<string, object> { ["Name"] = "Borin", ["World"] = "", ["Rating"] = 1712 },
});
  • 每一行都是独立的标签,各自以省略号截断;两行都不换行,因此单元格永远不会超出行高。
  • 两行都关闭了富文本,因此数据中的标记会以纯文本显示。
  • 排序和全局搜索只使用 key 的值。
  • 第二行为空时会获得 sus-hidden,标题单独占据该单元格。
  • 样式钩子:sus-table__cell--two-line(单元格)、sus-table__cell-title、sus-table__cell-sub。

表格 token ​

三个 token 决定表格外壳的尺寸。在你的皮肤或主题 USS 中设置它们:

Token默认值控制内容
--sk-table-header-underlaytransparent表头行后面的背景。Unity 的 MultiColumnListView 会用 Unity 主题绘制该区域;kit 只在 .sus-data-table 内部覆盖它,因此你自己的 MultiColumnListView 会保留主题。
--sk-table-cell-pad-x--sk-space-8每个单元格的左右内边距。默认遵循 density 阶梯。
--sk-table-cell-number-pad-x--sk-table-cell-pad-x仅数字单元格的左右内边距。它叠加在单元格包裹的内边距(--sk-table-cell-pad-x,默认每侧 8 px)之上,而不是替代它,因此要让短数字放进窄列,请同时设置两个 token。
css
.my-skin .sus-data-table {
    --sk-table-header-underlay: rgba(0, 0, 0, 0.35);
    --sk-table-cell-number-pad-x: 2px;
}

数字单元格 ​

默认情况下,数字单元格保持其自然宽度。它不会收缩,也从不显示省略号:比列更宽的数字会延伸进单元格内边距,而不是被截断。如果你的皮肤更想要省略号,请在同一个选择器上添加:

css
.my-skin .sus-data-table__cell.sus-table__cell--number {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

常见覆盖的皮肤钩子 ​

如果你的皮肤过去是手工修补表格,请改用内置钩子:

自定义变通做法内置钩子
带有较小第二行并重新开启换行的富文本标签SusHeaders.TwoLine → sus-table__cell-title / sus-table__cell-sub
重新绘制表头后面的灰色条--sk-table-header-underlay
窄列中数字被截成“2…”--sk-table-cell-number-pad-x(如需省略号,参见 数字单元格)

说明 ​

  • 需要工具栏、kind 预设或类型化单元格(SusCellType:text · number · icon · image · toggle · badge · progress · description · two-line · actions)时,优先用 SusDataTable 而不是 SusTable。
  • SusTableKind:MainList · Picker · ActionList · ReadOnly · Dev — 通过 ApplyKindDefaults 应用。
  • 行操作 / 选择 / 加载状态定义在控制器上(Options、RowActionRequested、Loading 等)。
  • 空 Items 显示内置空状态;设置 Loading 显示遮罩加载条。
  • 已知问题:带宽度预设的预设(SusHeaders.Number、Icon、Image、Active、Actions、Select)会忽略 WithWidth(...),因为 WidthToken 优先于 Width。如需精确宽度,请清除预设:var col = SusHeaders.Number("Rating").WithWidth(60f); col.WidthToken = null;。