← Back to Skills Marketplace
chenxiaoyu0124-web

AntV S2 海量数据表格指南

by chenxiaoyu0124-web · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ✓ Security Clean
145
Downloads
0
Stars
0
Active Installs
2
Versions
Install in OpenClaw
/install antd-table-s2-guide
Description
AntV S2 表格渲染千万级数据,支持透视、明细表、多维分析,提供性能优化和Vue3集成方案。
README (SKILL.md)

AntV S2 海量数据表格指南

核心概念

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

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

Vue3 集成模板

\x3Ctemplate>
  \x3Cdiv ref="containerRef" class="s2-container" />
\x3C/template>

\x3Cscript setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { PivotSheet } from '@antv/s2'

const containerRef = ref\x3CHTMLDivElement>()

let s2Instance: PivotSheet | null = null

onMounted(() => {
  const container = containerRef.value!
  s2Instance = new PivotSheet(container, s2Options)
  s2Instance.render()
})

onBeforeUnmount(() => {
  s2Instance?.dispose()
})
\x3C/script>

\x3Cstyle scoped>
.s2-container {
  width: 100%;
  height: 600px; /* 必须有明确高度 */
}
\x3C/style>

透视表配置

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)
})

踩坑记录

  1. 容器必须有明确高度,否则 S2 无法计算虚拟滚动区域
  2. frozenColCount 不要超过 3,冻结列越多渲染压力越大
  3. setData 会重新渲染,大数据量时配合防抖使用
  4. theme 修改要重新调用 setTheme(),不能直接改 options
  5. Vue3 中要在 onBeforeUnmount 调用 dispose(),否则内存泄漏
Usage Guidance
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 — the skill itself does not perform any network calls or require credentials.
Capability Assessment
Purpose & Capability
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.
Instruction Scope
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.
Install Mechanism
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.
Credentials
The skill declares no required environment variables, credentials, or config paths. There are no requests for secrets or unrelated API keys in the content.
Persistence & Privilege
always is false and the skill is user-invocable. It does not request persistent presence or attempt to modify other skills or system settings.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install antd-table-s2-guide
  3. After installation, invoke the skill by name or use /antd-table-s2-guide
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.1.0
新增定价,内容不变
v1.0.0
初始发布:Vue3集成+性能调优+踩坑
Metadata
Slug antd-table-s2-guide
Version 1.1.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 2
Frequently Asked Questions

What is AntV S2 海量数据表格指南?

AntV S2 表格渲染千万级数据,支持透视、明细表、多维分析,提供性能优化和Vue3集成方案。 It is an AI Agent Skill for Claude Code / OpenClaw, with 145 downloads so far.

How do I install AntV S2 海量数据表格指南?

Run "/install antd-table-s2-guide" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is AntV S2 海量数据表格指南 free?

Yes, AntV S2 海量数据表格指南 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does AntV S2 海量数据表格指南 support?

AntV S2 海量数据表格指南 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created AntV S2 海量数据表格指南?

It is built and maintained by chenxiaoyu0124-web (@chenxiaoyu0124-web); the current version is v1.1.0.

💬 Comments