首页龙虾技能列表 › AntV S2 海量数据表格指南

AntV S2 海量数据表格指南

v1.1.0

AntV S2 表格渲染千万级数据,支持透视、明细表、多维分析,提供性能优化和Vue3集成方案。

0· 74·0 当前·0 累计
下载技能包
License
MIT-0
最后更新
2026/4/6
安全扫描
VirusTotal
Pending
查看报告
OpenClaw
安全
high confidence
The skill is an instruction-only guide about AntV S2 usage and performance tuning; its requirements and instructions are consistent with that purpose and it does not request credentials, install code, or perform out-of-scope actions.
评估建议
This skill is a documentation-style guide and appears internally consistent. Before using code from the guide in production: (1) review and adapt the example fetch endpoints to point at your trusted backends (do not paste secrets into requests or query parameters), (2) verify package versions and compatibility with your project, (3) test large-data behavior in a development environment, and (4) note the metadata (author/licensing/pricing) in clawhub.json if you plan to purchase or distribute — t...
详细分析 ▾
用途与能力
The name/description (AntV S2 large-data table guide) matches the SKILL.md content: code samples, Vue3 integration, and performance tips. There are no unexpected required binaries, environment variables, or credentials.
指令范围
SKILL.md contains only documentation and example code for S2 usage, data loading patterns, and event handlers. The only network reference is an example fetch('/api/data?page=...'), which is a normal example for data loading and not an instruction to contact a hidden endpoint. The guide does not instruct reading local files, accessing unrelated env vars, or exfiltrating data.
安装机制
No install spec and no code files beyond documentation — this is the lowest-risk pattern (instruction-only). Nothing is downloaded or written to disk by the skill itself.
凭证需求
The skill declares no required environment variables, credentials, or config paths. There are no requests for secrets or unrelated API keys in the content.
持久化与权限
always is false and the skill is user-invocable. It does not request persistent presence or attempt to modify other skills or system settings.
安全有层次,运行前请审查代码。

License

MIT-0

可自由使用、修改和再分发,无需署名。

运行时依赖

无特殊依赖

版本

latestv1.1.02026/4/6

新增定价,内容不变

● Pending

安装命令 点击复制

官方npx clawhub@latest install antd-table-s2-guide
镜像加速npx clawhub@latest install antd-table-s2-guide --registry https://cn.clawhub-mirror.com

技能文档

核心概念

import { PivotSheet, TableSheet, S2Options, S2Event } from '@antv/s2'

// PivotSheet - 透视分析表(行头+列头交叉) // TableSheet - 明细表(扁平数据,无行列头)

Vue3 集成模板

透视表配置

const s2Options: S2Options = {
  width: 800,
  height: 600,
  hierarchyType: 'grid', // 'grid' | 'tree'

// 数据字段定义 fields: { rows: ['province', 'city'], // 行维度 columns: ['category', 'product'], // 列维度 values: ['sales', 'profit'], // 度量值 valueInCols: true, // 指标在列头展示 },

// 数据 data: rawData,

// 主题 theme: { name: 'default', palette: { // 自定义条件格式色阶 condition: { positive: { fill: '#29A294' }, negative: { fill: '#E86452' }, }, }, },

// 交互 interaction: { hoverHighlight: true, selectedCellsSpotlight: true, linkFields: ['product'], // 可点击的字段 }, }

性能优化

1. 虚拟滚动(大数据量必备)

const s2Options: S2Options = {
  // S2 默认开启虚拟滚动,但需要确保:
  // 1. 容器有明确高度
  // 2. 不要关闭 frozenRowCount / frozenColCount 中的大量行列
  frozenRowCount: 1,   // 只冻结表头
  frozenColCount: 0,   // 冻结列越多性能越差
  scrollSpeedRatio: {
    horizontal: 0.3,    // 水平滚动速度
    vertical: 0.3,
  },
}

2. 条件格式优化

// ❌ 避免:每个单元格都计算样式
// ✅ 正确:用内置条件格式规则
const conditions = {
  text: [
    {
      field: 'status',
      mapping: (value) => {
        if (value === '异常') return { fill: '#E86452', textFill: '#fff' }
        return {}
      },
    },
  ],
  background: [
    {
      field: 'sales',
      mapping: (value) => {
        // 用线性插值,不要用分段判断
        const ratio = Math.min(Math.abs(value) / 10000, 1)
        return { fill: rgba(232, 100, 82, ${ratio * 0.3}) }
      },
    },
  ],
}

3. 大数据量数据准备

// ❌ 前端一次性处理 10 万+ 行
// ✅ 分页加载 + 服务端聚合
async function loadData(page: number, size: number) {
  const res = await fetch(/api/data?page=${page}&size=${size})
  return res.json()
}

// S2 支持动态更新数据 s2Instance.setData(newData)

4. 减少不必要的重渲染

// ❌ 频繁更新
watch(searchQuery, () => {
  s2Instance.setData(filteredData) // 每次输入都触发
})

// ✅ 防抖更新 import { useDebounceFn } from '@vueuse/core' const debouncedUpdate = useDebounceFn((data) => { s2Instance.setData(data) }, 300)

watch(searchQuery, () => { debouncedUpdate(filteredData.value) })

明细表(TableSheet)

import { TableSheet } from '@antv/s2'

const tableSheet = new TableSheet(container, { fields: { columns: ['id', 'name', 'value', 'status', 'date'], }, data: tableData, // 明细表专用配置 style: { cellCfg: { width: 120, height: 36, }, }, })

常用事件

// 单元格点击
s2Instance.on(S2Event.DATA_CELL_CLICK, (event) => {
  console.log('clicked:', event)
})

// 链接字段点击 s2Instance.on(S2Event.GLOBAL_LINK_FIELD_JUMP, (data) => { window.open(data.fieldValue) })

// 排序 s2Instance.on(S2Event.RANGE_SORTED, (data) => { console.log('sorted:', data) })

踩坑记录

  • 容器必须有明确高度,否则 S2 无法计算虚拟滚动区域
  • frozenColCount 不要超过 3,冻结列越多渲染压力越大
  • setData 会重新渲染,大数据量时配合防抖使用
  • 主题 修改要重新调用 setTheme(),不能直接改 options
  • Vue3 中要在 onBeforeUnmount 调用 dispose(),否则内存泄漏
数据来源:ClawHub ↗ · 中文优化:龙虾技能库
OpenClaw 技能定制 / 插件定制 / 私有工作流定制

免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制

了解定制服务