Skip to content

VirtualTable 虚拟表格

AuVirtualTable 面向固定行高的大数据表格,只渲染视口和缓冲区中的行。列通过 JavaScript 对象配置,支持弹性宽度、左右固定、排序、格式化与具名插槽。

基础用法

10,000 行数据

支持切换刷新加载态;滚动时 DOM 中只保留当前可见行和 overscan 缓冲行。

当前渲染 1–0 行
名称
状态
更新时间
1
Aurora 任务 1
林晨
已完成
2026-08-01 10:30
2
Aurora 任务 2
周言
进行中
2026-08-02 10:30
3
Aurora 任务 3
陈夏
进行中
2026-08-03 10:30
4
Aurora 任务 4
林晨
进行中
2026-08-04 10:30
5
Aurora 任务 5
周言
已完成
2026-08-05 10:30
6
Aurora 任务 6
陈夏
进行中
2026-08-06 10:30
7
Aurora 任务 7
林晨
进行中
2026-08-07 10:30
8
Aurora 任务 8
周言
进行中
2026-08-08 10:30
9
Aurora 任务 9
陈夏
已完成
2026-08-09 10:30
10
Aurora 任务 10
林晨
进行中
2026-08-10 10:30
11
Aurora 任务 11
周言
进行中
2026-08-11 10:30
12
Aurora 任务 12
陈夏
进行中
2026-08-12 10:30
13
Aurora 任务 13
林晨
已完成
2026-08-13 10:30
正在刷新任务
vue
<template>
  <div class="virtual-table-demo">
    <div class="virtual-table-demo__actions">
      <AuButton size="small" @click="tableRef?.scrollToRow(5000, 'center')">定位第 5,001 行</AuButton>
      <AuButton size="small" :type="loading ? 'primary' : 'default'" @click="loading = !loading">
        {{ loading ? '结束刷新' : '模拟刷新' }}
      </AuButton>
      <span>当前渲染 {{ rendered.start + 1 }}–{{ rendered.end }} 行</span>
    </div>
    <AuVirtualTable
      ref="tableRef"
      :columns="columns"
      :data="rows"
      :height="360"
      :loading="loading"
      loading-text="正在刷新任务"
      stripe
      border
      @rows-rendered="rendered = $event"
    >
      <template #cell-status="{ value }">
        <span class="virtual-table-demo__status" :class="{ 'is-active': value === '进行中' }">
          {{ value }}
        </span>
      </template>
    </AuVirtualTable>
  </div>
</template>
<script setup>
import { ref } from 'vue';
import { AuButton, AuVirtualTable } from 'aurora-plus';
const tableRef = ref(null);
const loading = ref(true);
const rendered = ref({ start: 0, end: 0 });
const columns = [
  { key: 'id', title: '编号', dataKey: 'id', width: 90, fixed: 'left', sortable: true },
  { key: 'name', title: '名称', dataKey: 'name', width: 180, flexGrow: 1 },
  { key: 'owner', title: '负责人', dataKey: 'owner', width: 130, sortable: true },
  { key: 'status', title: '状态', dataKey: 'status', width: 110, align: 'center' },
  { key: 'updatedAt', title: '更新时间', dataKey: 'updatedAt', width: 160 },
];
const rows = Array.from({ length: 10000 }, (_, index) => ({
  id: index + 1,
  name: `Aurora 任务 ${index + 1}`,
  owner: ['林晨', '周言', '陈夏'][index % 3],
  status: index % 4 === 0 ? '已完成' : '进行中',
  updatedAt: `2026-08-${String(index % 28 + 1).padStart(2, '0')} 10:30`,
}));
</script>
<style scoped>
.virtual-table-demo {
  display: grid;
  gap: 10px;
}
.virtual-table-demo__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--au-color-text-secondary);
  font-size: var(--au-font-size-small);
}
.virtual-table-demo__status {
  color: var(--au-color-success);
}
.virtual-table-demo__status.is-active {
  color: var(--au-color-primary);
}
</style>

Column 配置

字段说明
key列唯一标识,也是具名插槽后缀
dataKey行对象字段路径,支持 profile.name
title / label表头文字
width / minWidth / maxWidth列宽边界,单位 px
flexGrow容器有剩余空间时的扩展比例
alignleft / center / right
fixedleft / right / truetrue 等同左固定
sortable开启列排序
sortMethod(leftRow, rightRow, column)自定义本地比较函数
formatter(row, column, value, index)文本格式化函数
class列单元格类名

Attributes

属性说明默认值
columns / data列配置 / 完整行数据[] / []
width / height表格外部尺寸100% / 400
rowHeight / headerHeight固定行高 / 表头高度40 / 36
overscan视口上下额外渲染行数6
rowKeykey 字段路径或函数id
rowClass行类名或 ({ row, rowIndex }) => string''
sortBy / v-model:sort-by{ key, order },order 为 ascending / descending / ''
defaultSort初始排序{ key: '', order: '' }
remoteSort只发出排序事件,不在组件内重排数据false
stripe / border斑马纹 / 单元格分隔线false
loading / loadingText加载状态与文字false / 加载中
emptyText / ariaLabel空数据文字 / 表格名称暂无数据 / 虚拟表格

Slots、Events 与 Exposes

keyname 时,可使用 #header-name="{ column }"#cell-name="{ row, column, value, index }"。另有 emptyloading 插槽。

事件包括 sort-changescrollrows-rendered({ start, end })row-clickrow-dblclickcell-click。组件暴露 scrollTo(options)scrollToTop(value?)scrollToLeft(value?)scrollToRow(index, align?)scrollContainerRef

行高必须与 rowHeight 一致;需要动态行高或合并单元格时应使用普通表格组件。

Aurora Plus · Vue 3 Component Library