logo

S2

  • Manual
  • API
  • Examples
  • Playground
  • ChangeLog
  • Productsantv logo arrow
  • 2.x
  • Introduction
  • Quick Start
  • Basic Tutorial
    • Base Concept
    • Sheet Type
      • Pivot Mode
        Updated
      • Table Mode
    • Conditions
      Updated
    • Totals
    • Sort
      • Custom Sort
        Updated
      • Group Sort
        Updated
    • Theme
      Updated
    • Tooltip
      Updated
    • Internationalization
    • 数据格式化
      New
    • Multi Line
      New
    • Pagination
      New
  • Advanced Tutorial
    • Advanced Tutorial
      • Link
      • Render Chart In Cell
      • Draw Chart With @antv/g2
    • Custom
      • Customize Hook
        Updated
      • Customize Tree
        New
      • Customize Icon
      • Customize Cell Alignment
      • Customize Cell Size
        Updated
      • Customize Order
      • Custom Collapse/Expand Nodes
    • Interaction
      • Basic Interaction
      • Custom Interaction
      • Hide Columns
      • Cell Resize
      • Merge Cell
      • Scroll
      • Copy
        New
      • Highlight and select cell
        New
    • Analyze Component
      • Introduction
        New
      • Advanced Sort
        Updated
      • Switcher
      • Export
        Updated
      • Pagination
      • Drill Down
    • Sheet Component
      • Editable Mode
      • Strategy Sheet
        Updated
    • HD Adapter
    • Get Instance
    • Get Cell Data
      Updated
    • Table adaptive
    • AntV/G Plugins
      New
    • Pivot Chart
      Experimental
    • Vue 3.0
  • Extended Reading
    • Data Process
      • Pivot
      • Table
    • Layout
      • Pivot
      • Table
    • Performance
      Updated
  • Contribution
  • FAQ
  • S2 2.0 Migration Guide

Quick Start

Previous
Introduction
Next
Base Concept

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

📦 install

npm | yarn install

# npm
$ npm install @antv/s2
# yarn
$ yarn add @antv/s2

Use React or Vue3 version

# React
$ yarn add @antv/s2 @antv/s2-react
# Vue3
$ yarn add @antv/s2 @antv/s2-vue

Browser introduction (deprecated)

Check out the example:

Edit @antv/s2 import in browser

We provide the UMD compilation file of the dist directory, import dist/s2.min.js , and access the global variable window.S2

<script src="./dist/s2.min.js"></script>
<script>
async function run() {
const s2 = new S2.PivotSheet(container, s2DataConfig, s2Options);
await s2.render();
}
run();
</script>

All exports are uniformly mounted under the global variable window.S2

<script type="module">
- import { S2Event, PivotSheet, TableSheet } from '@antv/s2'
+ const { S2Event, PivotSheet, TableSheet } = S2
</script>

If you are using the React version @antv/s2-react , or Vue3 version @antv/s2-vue , additional style files need to be introduced

<link rel="stylesheet" href="./dist/style.min.css"/>

You can also use CDN directly (recommended), such as UNPKG or preview

<script src="https://unpkg.com/@antv/s2/dist/s2.min.js"></script>
// React 需额外引入样式:
<link rel="stylesheet" href="https://unpkg.com/@antv/s2-react/dist/s2-react.min.css"/>
// Vue3 版本 需额外引入样式:
<link rel="stylesheet" href="https://unpkg.com/@antv/s2-vue/dist/s2-vue.min.css"/>

If you need to be compatible with IE , you need to introduce polyfill compatibility.

🔨 use

There are three ways to create an S2 table, the basic class version (s2-core) and the React and Vue3 version based on the core layer package

Note

There are three ways to create an S2 table: the basic version @antv/s2 and the React and Vue3 versions wrapped based on @antv/s2:

  1. Basic version @antv/s2: Developed based on Canvas and AntV/G 6.0, providing basic table display/interaction capabilities.

Dependencies: None

  1. React version @antv/s2-react: Wrapped based on React 18 and @antv/s2, compatible with React 16/17 versions, and provides supporting analysis components (@antv/s2-react-components).

Dependencies:

"peerDependencies": {
"@antv/s2": "^2.0.0",
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
}
  1. Vue version @antv/s2-vue: Wrapped based on Vue3, @antv/s2, and [email protected]. Maintenance Discontinued

Dependencies:

"peerDependencies": {
"@antv/s2": "^2.0.0",
"ant-design-vue": "^3.2.0",
"vue": ">=3.x"
}

In other words, @antv/s2 is framework-agnostic with no additional dependencies. You can use it in any framework like Vue, Angular, etc.

Package NameStable VersionPackage SizeDownloads
@antv/s2latestsizedownload
@antv/s2-reactlatestsizedownload
@antv/s2-react-componentslatestsizedownload
@antv/s2-vue (Discontinued)latestsizedownload

How to get notifications for new version releases?

  • Subscribe to: https://github.com/antvis/S2/releases.atom to receive notifications of new version releases.
  • Watch the S2 repository, select Custom - Releases to receive push notifications.

preview

basic class

1. Data preparation

s2DataConfig
 const&nbsp;s2DataConfig&nbsp;=&nbsp;{
&nbsp;&nbsp;fields:&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;rows:&nbsp;['province',&nbsp;'city'],
&nbsp;&nbsp;&nbsp;&nbsp;columns:&nbsp;['type'],
&nbsp;&nbsp;&nbsp;&nbsp;values:&nbsp;['price'],
&nbsp;&nbsp;},
&nbsp;&nbsp;data:&nbsp;[
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"浙江",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"杭州",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"笔",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price:&nbsp;"1",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"浙江",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"杭州",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"纸张",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price:&nbsp;"2",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"浙江",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"舟山",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"笔",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price:&nbsp;"17",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"浙江",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"舟山",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"纸张",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price:&nbsp;"6",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"吉林",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"长春",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"笔",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price:&nbsp;"8",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"吉林",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"白山",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"笔",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price:&nbsp;"12",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"吉林",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"长春",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"纸张",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price:&nbsp;"3",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"吉林",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"白山",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"纸张",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;price:&nbsp;"25",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"浙江",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"杭州",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"笔",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost:&nbsp;"0.5",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"浙江",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"杭州",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"纸张",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost:&nbsp;"20",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"浙江",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"舟山",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"笔",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost:&nbsp;"1.7",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"浙江",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"舟山",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"纸张",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost:&nbsp;"0.12",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"吉林",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"长春",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"笔",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost:&nbsp;"10",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"吉林",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"白山",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"笔",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost:&nbsp;"9",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"吉林",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"长春",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"纸张",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost:&nbsp;"3",
&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;province:&nbsp;"吉林",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;city:&nbsp;"白山",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;"纸张",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost:&nbsp;"1",
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;]
};

2. Configuration item preparation

const s2Options = {
width: 600,
height: 480
}

3. Rendering

<div id="container"></div>
import { PivotSheet } from '@antv/s2';
async function run() {
const container = document.getElementById('container');
const s2 = new PivotSheet(container, s2DataConfig, s2Options);
await s2.render(); // return Promise
}
run();

4. Results

React version

S2 provides an out-of-the-box React version [table component] (/examples/gallery#category-table component), as well as a wealth of supporting analysis components to help developers quickly meet business analysis needs.

Table components use

import React from 'react';
import ReactDOM from 'react-dom';
import { SheetComponent } from '@antv/s2-react';
import '@antv/s2-react/dist/s2-react.min.css';
const container = document.getElementById('container');
ReactDOM.render(
<SheetComponent
dataCfg={s2DataConfig}
options={s2Options}
/>,
document.getElementById('container'),
);

Precautions

React version分析组件such as高级排序,导出,下钻, Tooltip and other components are developed based on antd component library. If you want to use it, you need to install it additionally and introduce the corresponding style

yarn add antd @ant-design/icons

​📊 Check out the React version pivot table demo .

Vue3 version

S2 also provides an out-of-the-box Vue3 version of the table component to help developers quickly meet business analysis needs.

Table components use

// App.vue
<script lang="ts">
import type { S2DataConfig, S2Options } from '@antv/s2';
import { SheetComponent } from '@antv/s2-vue';
import { defineComponent, onMounted, reactive, ref, shallowRef } from 'vue';
import "@antv/s2-vue/dist/s2-vue.min.css";
export default defineComponent({
setup() {
// dataCfg 数据字段较多,建议使用 shallow, 如果有数据更改直接替换整个对象
const dataCfg = shallowRef(s2DataConfig);
const options: S2Options = reactive(s2Options);
return {
dataCfg,
options,
};
},
components: {
SheetComponent,
},
});
</script>
<template>
<SheetComponent :dataCfg="dataCfg" :options="options" />
</template>

render component

import { createApp } from 'vue';
import App from './App.vue';
createApp(App).mount('#app');

Precautions

Vue3 version分析组件such as:高级排序,导出,下钻, Tooltip and other components are developed based on the ant-design-vue component library. If you want to use it, you need to install it additionally and introduce the corresponding style

yarn add ant-design-vue
import "@antv/s2-vue/dist/s2-vue.min.css";

​📊 Check out the Vue3 version pivot table demo .

⌨️ Local development

Eager to contribute? View contribution guidelines

S2 uses pnpm as package manager

git clone [email protected]:antvis/S2.git
cd S2
# 切换到 2.x 分支
git checkout next
# 安装依赖
pnpm install # 或者 pnpm bootstrap
# 打包
pnpm build
# 调试 s2-core
pnpm core:start
# 调试 s2-react
pnpm react:Playground
# 调试 s2-vue
pnpm vue:Playground
# 单元测试
pnpm test
# 代码风格和类型检测
pnpm lint
# 本地启动官网
pnpm site:start