Loading...
This document will help you upgrade from S2 1.x to S2 2.x.
The original websites https://s2.antv.vision and https://antv-s2.gitee.io are no longer maintained. Please visit the latest URL to ensure you're not viewing outdated documentation.
v1 website has moved to https://s2-v1.antv.antgroup.com.v2 website.What is dist-tag?
S2 2.0 official version has been released. Now the latest dist-tag on npm defaults to 2.x version:
@antv/s2@latest => @antv/[email protected]
@antv/s2@latest => @antv/[email protected]
If installing without specifying a version, be careful not to accidentally install the new 2.0 version.
1.x is now discontinued, will no longer be updated, bugs fixed, or new features added.@antv/s2-vue is now discontinued. Due to limited resources and maintenance costs, combined with package download volume considerations, it will no longer be updated after 2.0.0 official release. Please encapsulate based on @antv/s2 yourself or fork the repository for secondary development of community versions.Please upgrade to 2.x version according to the Migration Guide.
If you are using the beta version 2.0.0-next.x, pay attention to these additional incompatible changes when upgrading to 2.0 official release:
Install using npm or yarn or pnpm
# npm$ npm install @antv/s2 --save# yarn$ yarn add @antv/s2# pnpm$ pnpm add @antv/s2
npm install @antv/s2 @antv/s2-react --save
npm install @antv/s2 @antv/s2-react-components antd @ant-design/icons --save
@antv/s2-vue has been discontinued. Due to limited resources and considering factors such as maintenance costs and package download volume, updates will no longer be provided after version 2.0.0. Please create your own wrapper based on @antv/s2, or fork the repository to develop a community version.
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:
@antv/s2: Developed based on Canvas and AntV/G 6.0, providing basic table display/interaction capabilities.Dependencies: None
@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"}
@antv/s2-vue: Wrapped based on Vue3, @antv/s2, and [email protected]. Maintenance DiscontinuedDependencies:
"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 Name | Stable Version | Package Size | Downloads |
|---|---|---|---|
| @antv/s2 | |||
| @antv/s2-react | |||
| @antv/s2-react-components | |||
| @antv/s2-vue (Discontinued) |
Watch the S2 repository, select Custom - Releases to receive push notifications.Features marked with New and Updated in the official documentation indicate new functionality. You can also check out the official blog post S2 2.0: A New Era for Data Tables.
ESModule/CommonJSThe ESModule (esm) and CommonJS (lib) build outputs for all packages have been changed from Bundle to Bundless. Dependent sub-modules are now directly copied without compilation to better support code tree shaking and reduce package size.
UMDThe UMD (dist) build outputs remain as single Bundle files, but filenames and global variable names have been adjusted:
| Package Name | Filename (Before) | Filename (After) |
|---|---|---|
@antv/s2 | dist/index.min.js dist/style.min.css | dist/s2.min.css dist/s2.min.css |
@antv/s2-react | dist/index.min.js dist/style.min.css | dist/s2-react.min.css dist/s2-react.min.css |
@antv/s2-vue | dist/index.min.js dist/style.min.css | dist/s2-vue.min.css dist/s2-vue.min.css |
| Package Name | Global Variable (Before) | Global Variable (After) |
|---|---|---|
@antv/s2 | S2 | S2 |
@antv/s2-react | S2-React | S2React |
@antv/s2-vue | S2-Vue | S2Vue |
AntV/G 6.0The table rendering engine has been upgraded to G 6.0 major version to stay in sync with other AntV technology stacks. Rendering is now asynchronous.
- s2.render()+ await s2.render()
If you use custom G shapes in your business scenarios, such as custom rectangles, images, etc., or other capabilities, please note the replacements. For details, see G's official documentation.
+ import { Image } from '@antv/g';+ this.appendChild(new Image({ style: {} }))- this.addShape('image', { attrs: {} });
The same applies to other shapes.
In 1.x, we passed properties like supportsCSSTransform and devicePixelRatio from S2Options to G.
In 2.x:
devicePixelRatio and supportsCSSTransform (supportCSSTransform).transformCanvasConfig to support passing G configurations and registering plugins. See Register AntV/G Plugins documentation for details.const s2Options = {transformCanvasConfig(renderer) {renderer.setConfig({ enableDirtyCheck: true })renderer.registerPlugin(new PluginA11y({ enableExtractingText: true }));return {devicePixelRatio: 2};},}
rowCfg/colCfg/cellCfg to rowCell/colCell/dataCell.const s2Options = {style: {- rowCfg: {},- colCfg: {},- cellCfg: {},+ rowCell: {},+ colCell: {},+ dataCell: {},}}
widthByFieldValue, added widthByField.export interface BaseCellStyle {width?: number | (node) => number;- height?: number;+ height?: number | (node) => number;- widthByFieldValue?: Record<string, number>;+ widthByField?: Record<string, number>;heightByField?: Record<string, number>;}
widthByField and heightByField support both dimension id and dimension field.See Custom Cell Width/Height documentation for details.
row/col/data/corner to rowCell/colCell/dataCell/cornerCell.const s2Options = {tooltip: {- row: {},- col: {},- data: {},- corner: {},+ rowCell: {},+ colCell: {},+ dataCell: {},+ cornerCell: {},}}
showTooltip and renderTooltip to enable and render.const s2Options = {tooltip: {- showTooltip: true,- renderTooltip: () => new CustomTooltip(),+ enable: true,+ render: () => new CustomTooltip(),}}
Removed enterable property, changed showSingleTips to onlyShowCellText, changed onlyMenu to onlyShowOperator
s2.showTooltip({options: {- enterable: true,- showSingleTips: true,+ onlyShowCellText: true,- onlyMenu: true,+ onlyShowOperator: true},});
See Tooltip documentation for details.
interaction.copy, added customTransformer for custom transformations.const s2Options = {interaction: {- enableCopy: true,- copyWithHeader: true,- copyWithFormat: true+ copy: {+ enable: true,+ withHeader: true,+ withFormat: true,+ customTransformer: () => {}+ },}}
copyData, added asyncGetAllData, asyncGetAllPlainData, asyncGetAllHtmlData and other APIs to support asynchronous data retrieval.- const data = copyData(spreadsheet, '\t', false)+ const data = await asyncGetAllData({+ sheetInstance: s2,+ split: '\t',+ formatOptions: false,+ async: true,});
copyToClipboard from sync to async.- const data = copyToClipboard(data: string, sync: boolean)+ const data = copyToClipboard(data: Copyable | string, async: boolean)
See Copy and Export documentation for details.
row/col/data to rowCell/colCell/dataCell.const s2Options = {interaction: {- brushSelection: {- row: false,- col: false,- data: true,- },+ brushSelection: {+ rowCell: true,+ colCell: true,+ dataCell: true,+ }}}
See Basic Interactions documentation for details.
Changed iconsNames to icons, deprecated action, added onClick and onHover.
const s2Options = {headerActionIcons: [{- iconNames: ['SortDown'],- action: () => {}+ icons: ['SortDown'],+ onClick: () => {}+ onHover: () => {}},],}
Now supports configuring position (icon position relative to text) and fill (color configuration), and allows setting independent displayCondition and defaultHide for individual icons.
const s2Options = {headerActionIcons: [{+ icons: [{+ name: 'SortDown',+ position: 'right',+ fill: '#000',+ displayCondition: () => {},+ defaultHide: () => {},+ }]},],}
See Custom Icon documentation for details.
Changed svg to src for API consistency.
const s2Options = {customSVGIcons: [{name: 'CustomIcon',- svg: 'https://gw.alipayobjects.com/zos/bmw-prod/f44eb1f5-7cea-45df-875e-76e825a6e0ab.svg',+ src: 'https://gw.alipayobjects.com/zos/bmw-prod/f44eb1f5-7cea-45df-875e-76e825a6e0ab.svg',},]}
Deprecated rowExpandDepth/collapsedRows/hierarchyCollapse, replaced with more semantic expandDepth/collapseFields/collapseAll.
const s2Options = {hierarchyType: 'tree',style: {- rowExpandDepth: 0,- collapsedRows: {},- hierarchyCollapse: true,+ rowCell: {+ expandDepth: 0,+ collapseFields: {},+ collapseAll: true}},}
treeRowsWidth, replaced with rowCell.treeWidth.
const s2Options = {hierarchyType: 'tree',style: {- treeRowsWidth: 200+ rowCell: {+ treeWidth: 200,+ }},}
customTree and customTreeItems have been deprecated.The original way of customizing tree structures has been deprecated. Now custom structures support both flat and tree modes.
const s2Options = {- hierarchyType: 'customTree',+ hierarchyType: 'tree',}const s2DataConfig = {fields: {- customTreeItems: [- {- key: 'custom-node-1',- title: 'Custom Node A',- description: 'Custom Node A Description',- children: []- }+ rows: [+ {+ field: 'custom-node-1',+ title: 'Custom Node A',+ description: 'Custom Node A Description',+ children: []+ }]}}
See Custom Row/Column Header Grouping documentation for details.
RowCellRemoved LAYOUT_AFTER_COLLAPSE_ROWS
- S2Event.LAYOUT_TREE_ROWS_COLLAPSE_ALL+ S2Event.ROW_CELL_ALL_COLLAPSED- S2Event.LAYOUT_COLLAPSE_ROWS- S2Event.LAYOUT_AFTER_COLLAPSE_ROWS+ S2Event.ROW_CELL_COLLAPSED
Now when row header node icons are expanded/collapsed, the corner header icon state (expand all/collapse all) will be synchronized accordingly.
Pivot table and detail table row/column freezing configurations are now consolidated under frozen.
In pivot tables, frozenFirstRow is replaced by rowCount: 1. In detail tables with multi-level column headers, freezing in 1.x was based on the topmost node, while in 2.x it's based on the number of leaf nodes.
const s2Options = {- frozenRowHeader: true,- frozenFirstRow: true,- frozenRowCount: 1;- frozenColCount: 1;- frozenTrailingRowCount: 1;- frozenTrailingColCount: 1;+ frozen: {+ rowHeader: true,+ rowCount: 1;+ colCount: 1;+ trailingRowCount: 1;+ trailingColCount: 1;+ }}
rowHeader now supports passing a number. If a numeric value is provided, it enables row header freezing with a custom maximum frozen width (0 - 1).
const s2Options = {frozen: {- rowHeader: true,+ rowHeader: true,+ rowHeader: 0.5,}}
const s2Options = {- hdAdapter: true,+ hd: true,}
Text field marking capabilities now align with Text Theme Configuration, supporting font size, opacity, alignment, and other configurations.
const s2Options = {conditions: {text: [{field: 'city',mapping() {return {fill: '#DB6BCF',+ fontSize: 16,+ opacity: 0.8,+ textAlign: 'right',};},},]},}
See Field Marking documentation and Text Marking Examples for details.
Serial number related configurations are now consolidated under seriesNumber.
const s2Options = {- showSeriesNumber: true,- seriesNumberText: 'No.'+ seriesNumber: {+ enable: true,+ text: 'No.'+ }}
1.x, width/height adjustments affected all cells. 2.x adds rowResizeType/colResizeType to choose whether adjustments affect current, selected, or all cells.const s2Options = {interaction: {resize: {+ rowResizeType: 'current', // 'all' | 'selected'+ colResizeType: 'current' // 'all' | 'selected'}}}
See Row/Column Width/Height Adjustment documentation for details.
layoutResult is deprecated, use s2.facet.getLayoutResult() to dynamically get results, which now includes corner nodes (cornerNodes) and serial number nodes (seriesNumberNodes).- s2.facet.layoutResult+ s2.facet.getLayoutResult()
getCellMeta has been removed from layoutResult and moved to the facet level. Now layoutResult only contains layout nodes.- s2.facet.layoutResult.getCellMeta(rowIndex, colIndex)+ s2.facet.getCellMeta(rowIndex, colIndex)
layoutResult now includes corner nodes (cornerNodes) and serial number nodes (seriesNumberNodes).export interface LayoutResult {colNodes: Node[];colLeafNodes: Node[];colsHierarchy: Hierarchy;rowNodes: Node[];rowsHierarchy: Hierarchy;rowLeafNodes: Node[];- getCellMeta: (rowIndex: number, colIndex: number) => ViewMeta+ seriesNumberNodes?: Node[];+ cornerNodes?: Node[];}
cellMeta now including query/rowQuery/colQuery for both.Pivot table:
{rowQuery: {"province": "Zhejiang","city": "Ningbo"},colQuery: {"sub_type": "Sofa","type": "Furniture","$$extra$$": "number"},+ query: {+ "province": "Zhejiang",+ "city": "Ningbo",+ "sub_type": "Sofa",+ "type": "Furniture",+ "$$extra$$": "number"+ }}
Detail table:
{+ rowQuery: {+ "rowIndex": 1,+ },+ colQuery: {+ "colIndex": 2,+ },+ query: {+ "rowIndex": 1,+ "colIndex": 2+ }}
s2.getContentHeight() is deprecated, moved to s2.facet.getContentHeight().- s2.getContentHeight()+ s2.facet.getContentHeight()+ s2.facet.getContentWidth()
s2.facet namespace. Added rich syntactic sugar.- s2.getRowNodes()- s2.getRowLeafNodes()- s2.getColumnLeafNodes()- s2.getColumnNodes()+ s2.facet.getRowNodes()+ s2.facet.getRowLeafNodes()+ s2.facet.getColLeafNodes()+ s2.facet.getColNodes()
See Get Cell Data and BaseFacet documentation for details.
The render function's parameter has been expanded from boolean to boolean | object. When boolean, it's equivalent to { reloadData: boolean }
- s2.render(true)- s2.render(false)- s2.render(false, { reBuildHiddenColumnsDetail: false })+ s2.render({ reloadData: true }) // equivalent to s2.render(true)+ s2.render({ reloadData: false }) // equivalent to s2.render(false)+ s2.render({+ reloadData: false,+ rebuildHiddenColumnsDetail: false,+ });
reBuildDataSet renamed to rebuildDataSet:
reBuildHiddenColumnsDetail renamed to rebuildHiddenColumnsDetail:
s2.render({- reBuildDataSet: false,+ rebuildDataSet: false,- reBuildHiddenColumnsDetail: false,+ rebuildHiddenColumnsDetail: false,});
Total-related configurations now consistently include grandTotals and subTotals prefixes to avoid ambiguity.
const s2Options = {totals: {row: {- calcTotals: {}.- reverseLayout: true,- label: 'Total'- subLabel: 'Subtotal'- totalsGroupDimensions: [],- reverseSubLayout: true,+ calcGrandTotals: {}.+ reverseGrandTotalsLayout: true,+ grandTotalsLabel: 'Total',+ subTotalsLabel: 'Subtotal',+ grandTotalsGroupDimensions: [],+ reverseSubTotalsLayout: true};}}
Multi-column text drawing function drawObjectText renamed to drawCustomContent.
- import { drawObjectText } from '@antv/s2'+ import { drawCustomContent } from '@antv/s2'
For data with multiple values, now expects all values information to be included in a single data item.
{fields: {rows: ["province", "city"],columns: ["type", "subType"],values: ["number1", "number2"],}}
- [- {- province: 'Liaoning',- city: 'Dazhou',- type: 'Table',- subType: 'Furniture',- number1: 3482.28,- },- {- province: 'Liaoning',- city: 'Dazhou',- type: 'Table',- subType: 'Furniture',- number2: 34,- },- ];+ [+ {+ province: 'Liaoning',+ city: 'Dazhou',+ type: 'Table',+ subType: 'Furniture',+ number1: 3482.28,+ number2: 34,+ },+ ];
string to CustomTreeNode | string.- s2.dataSet.getField(field: string)- s2.dataSet.getFieldMeta(field: string)- s2.dataSet.getFieldName(field: string)- s2.dataSet.getFieldFormatter(field: string)+ s2.dataSet.getField(field: CustomTreeNode | string)+ s2.dataSet.getFieldMeta(field: CustomTreeNode | string)+ s2.dataSet.getFieldName(field: CustomTreeNode | string)+ s2.dataSet.getFieldFormatter(field: CustomTreeNode | string)
- s2.dataSet.getCellData(params: CellDataParams)+ s2.dataSet.getCellData(params: GetCellDataParams)- s2.dataSet.getMultiData(query: DateType, params: MultiDataParams)- s2.dataSet.getMultiData(query: DataType, isTotals?: boolean, isRow?: boolean, drillDownFields?: string[], includeTotalData:boolean)+ s2.dataSet.getCellMultiData(params: GetCellMultiDataParams)
See Get Cell Data documentation for details.
totalData merged with data, totalData configuration no longer needed.
{- data: [...],- totalData: [...],+ data: [...data, ...totalData],}
this.meta.data structure changes:
{- "number": 7789,- "province": "Zhejiang",- "city": "Hangzhou",- "type": "Furniture",- "sub_type": "Table",+ "extraField": "number",+ "raw": {+ "number": 7789,+ "province": "Zhejiang",+ "city": "Hangzhou",+ "type": "Furniture",+ "sub_type": "Table"+ },+ "$$extra$$": "number",+ "$$value$$": 7789,+ "$$origin$$": {+ "number": 7789,+ "province": "Zhejiang",+ "city": "Hangzhou",+ "type": "Furniture",+ "sub_type": "Table"+ }}
See CellData documentation for details.
In 1.x, row/column header brush selection state was brushSelected, while value cell brush selection state was selected. In 2.x, these have been further unified and differentiated:
s2.interaction.getState()// Row header- stateName: "brushSelected"+ stateName: "rowCellBrushSelected"// Column header- stateName: "brushSelected"+ stateName: "colCellBrushSelected"// Value cells- stateName: "selected"+ stateName: "dataCellBrushSelected"
In 1.x, select all was essentially highlighting, with only style updates but no actual selection. In 2.x, this has been changed to the correct semantics, and selected cells can be retrieved.
s2.interaction.selectAll()- s2.interaction.getActiveCells() // []+ s2.interaction.getActiveCells() // [CellA, CellB]
selectHeaderCell changed to changeCell, supporting selection of all cell types. Also supports syntactic sugar for selection (selectCell) and highlighting (highlightCell).
- s2.interaction.selectHeaderCell(selectHeaderCellInfo: SelectHeaderCellInfo)+ s2.interaction.changeCell(options: ChangeCellOptions)+ s2.interaction.selectCell(cell: S2CellType)+ s2.interaction.highlightCell(cell: S2CellType)
Also supports animate (whether to show scroll animation) and skipScrollEvent (whether to trigger scroll event) configurations.
s2.interaction.selectCell(cell, {animate: true,skipScrollEvent: true})
See Highlight/Select Cell documentation for details.
Scroll API s2.updateScrollOffset removed, unified under s2.interaction namespace. Also supports syntactic sugar like scrollToCell and scrollToTop.
- s2.updateScrollOffset(offsetConfig: ScrollOffsetConfig)+ s2.interaction.scrollTo(offsetConfig: ScrollOffsetConfig)
Also supports skipScrollEvent (whether to trigger scroll event) configuration.
s2.interaction.scrollTo({+ skipScrollEvent: false})
See Scroll documentation for details.
- import { getSafetyOptions, getSafetyDataConfig } from '@antv/s2'+ import { setupOptions, setupDataConfig } from '@antv/s2'
In addition to supporting cell empty data placeholders, now supports configuring detail table empty data states, similar to Ant Design's Empty component empty state effect. Configuration is separated into cell and empty to distinguish between the two states.
const s2Options = {- placeholder: "-",+ placeholder: {+ cell: '-'+ }}
const s2Options = {+ placeholder: {+ empty: {+ icon: 'Empty',+ description: 'No Data'+ }+ }}
See Custom Empty Data Placeholder and Custom Cell Empty Data Placeholder examples.
- import { ROOT_ID, ID_SEPARATOR } from '@antv/s2'+ import { ROOT_NODE_ID, NODE_ID_SEPARATOR } from '@antv/s2'
If you're using these, please note the changes. See source code definition for details.
Added second parameter spreadsheet to maintain consistency with other cells.
const s2Options = {width: 600,- dataCell: (viewMeta) => {- return new CustomDataCell(viewMeta, viewMeta.spreadsheet);- }+ dataCell: (viewMeta, spreadsheet) => {+ return new CustomDataCell(viewMeta, spreadsheet);+ }}
column headers and values (with customizable rules).key changed to field, cellData changed to meta.s2.on(S2Event.GLOBAL_LINK_FIELD_JUMP, (data) => {- const { key, cellData, record } = data;+ const { field, meta, record } = data;});
See Link Jump documentation for details.
In 1.x, dimension values were converted to strings, so empty values (null) would be converted to "null", making it impossible to get the original dimension value. In 2.x, special identifiers are added for these cases to correctly identify null cases, original dimension values, and empty value placeholder logic.
{- id: 'root[&]null',- value: 'null'+ id: 'root[&]$$null$$',+ value: null}
- dataCell.valueRangeByField+ dataCell.getValueRange()
When no default values are set for split line color and opacity, they now default to match the cell border of their corresponding area.
splitLine: {- horizontalBorderColor: basicColors[12],- horizontalBorderColorOpacity: 0.2,- verticalBorderColor: basicColors[12],- verticalBorderColorOpacity: 0.25,}
paddingTop and paddingBottom adjusted to 8px.
{- top: 4,+ top: 8,- bottom: 4,+ bottom: 8}
The 2.0 official version removes the antd dependency, making the component internally lighter and no longer constrained by project antd versions, enabling smoother upgrades. Self-combination is recommended.
header property removed, related configurations (switcher, export, advancedSort) and corresponding components moved to @antv/s2-react-components, can be imported separately as needed.
<SheetComponent- header={{- title: "",- description: "",- switcher: { open: true },- export: { open: true },- advancedSort: { open: true },- }}/>
SheetComponent no longer wraps antd's <ConfigProvider /> global configuration component. You can wrap <ConfigProvider /> component externally to avoid compatibility issues with different antd versions.
import { ConfigProvider } from 'antd'<SheetComponent>- <ConfigProvider /></SheetComponent>+ <ConfigProvider>+ <SheetComponent />+ </ConfigProvider>
import { Spin } from 'antd'<SheetComponent>- <Spin /></SheetComponent>+ <Spin>+ <SheetComponent />+ </Spin>
In 1.x, <SheetComponent /> internally wrapped antd's <Spin /> component. This has been removed and no longer has a loading effect. Added onLoading, allowing you to wrap related components externally for combined use.
Generally, onLoading's effect is not very noticeable, it's recommended to control the loading effect based on the business-side API request status.
import { Spin } from 'antd'function App() {const [loading, setLoading] = React.useState(false)return (<Spin spinning={loading}><SheetComponent onLoading={setLoading} /></Spin>)}
showPagination property removed.- <SheetComponent showPagination />
pagination property, the table internally encapsulates S2's internal pagination update logic, can be used with any pagination component, such as antd's <Pagination />.import { Pagination } from 'antd';function App() {return (<SheetComponent options={s2Options}>{({ pagination }) => (// Use with any paginator: like antd's Pagination component<Paginationsize="small"showTotal={(total) => `Total ${total} items`}{...pagination}/>)}</SheetComponent>)}
- import { AdvancedSort } from '@antv/s2-react';+ import { AdvancedSort } from '@antv/s2-react-components';
sheet changed to sheetInstance
- <AdvancedSort sheet={s2} />+ <AdvancedSort sheetInstance={s2} />
See Advanced Sort documentation for details.
- import { Switcher } from '@antv/s2-react';+ import { Switcher } from '@antv/s2-react-components';
Added icon configuration, changed title meaning, no longer used for custom entry, use children instead.
- <Switcher title={<Button>Switch Dimension</Button>} />+ <Switcher title="Switch Dimension" icon={<SwapOutlined/>} />+ <Switcher>+ <Button>Switch Dimension</Button>+ </Switcher>
See Dimension Switcher documentation for details.
- import { Export } from '@antv/s2-react';+ import { Export } from '@antv/s2-react-components';
- <Export syncCopy={true} sheet={s2} />+ <Export async={false} sheetInstance={s2} />
icon property removed, supports custom children.
- <Export icon={<MoreOutlined/> } />+ <Export><Button type="text"><MoreOutlined /></Button></Export>
Copy Original Data and Copy Formatted Data now write both text/plain and text/html data to the clipboard.onCopySuccess/onCopyError, onDownloadSuccess/onDownloadError APIs, removed successText/errorText, operations no longer show message tips by default.<Export- successText="Operation successful"- errorText="Operation successful"+ onCopySuccess={(data) => {+ console.log('copy success:', data);+ }}+ onCopyError={(error) => {+ console.log('copy failed:', error);+ }}+ onDownloadSuccess={(data) => {+ console.log('download success', data);+ }}+ onDownloadError={(error) => {+ console.log('download failed:', error);+ }}/>
StrategyExport component, suitable for trend analysis table data copying and exporting, used the same way as Export.import { StrategyExport } from '@antv/s2-react-components';
See Export documentation for details.
- import { DrillDown } from '@antv/s2-react';+ import { DrillDown } from '@antv/s2-react-components';
- <DrillDown titleText="Drill Down" clearButtonText="Clear" />+ <DrillDown title="Drill Down" clearText="Clear" />
DrillDown configuration panel through render property.+ import { DrillDown } from '@antv/s2-react-components';function App() {return (<SheetComponentsheetType="pivot"options={s2Options}partDrillDown={{+ render: (props) => <DrillDown {...props} />,}}/>)}
See Dimension Drill Down documentation for details.
antd's Input.TextArea component replaced with native textarea.
+ <Input.TextArea />- <textarea />
render, final effect remains the same, default menu configuration (props) provided, can adjust usage based on project's actual antd@v4 or antd@v5 version.import { Menu } from 'antd'const s2Options = {tooltip: {operation: {menu: {render: (props) => {return <Menu {...props} />;},}}}}
Menu items moved under menu
const s2Options = {tooltip: {operation: {- onClick: (cell) => {},- menus: [- {- key: 'custom-a',- text: 'Operation 1',- icon: 'Trend',- onClick: (cell) => {},- visible: (cell) => true,- children: [],- }- ],+ menu: {+ onClick: (info, cell) => {},+ items: [+ {+ key: 'custom-a',+ label: 'Operation 1',+ icon: 'Trend',+ onClick: (info, cell) => {},+ visible: (info, cell) => true,+ children: [],+ }+ ],+ },},},};<SheetComponent options={s2Options} />
Also, when calling via API, defaultSelectedKeys changed to selectedKeys.
s2.showTooltip({options: {operator: {menu: {- defaultSelectedKeys: ['key-1'],+ selectedKeys: ['key-1'],},},},});
See Tooltip and Group Sort documentation for details.
React 19 has released its RC version, future compatibility will depend on circumstances.
Version 2.x of @antv/s2-react is adapted for React 18, while maintaining compatibility with React 16 and 17.
Since [email protected] has been discontinued, the analysis component @antv/s2-react-components is developed based on [email protected] by default. Although it uses basic components, full compatibility with [email protected] depends on the differences between the two versions.
For projects using [email protected], or depending on other libraries that indirectly depend on [email protected], where upgrading to [email protected] is not possible due to various historical reasons, you can temporarily transition using multi-version coexistence.
// $ npm install --save antd-v5@npm:antd@5{"antd": "4.x","antd-v5": "npm:antd@5"}
Use webpack's built-in NormalModuleReplacementPlugin or custom webpack plugin to specify that @antv/s2-react-components uses antd-v5, no modifications needed, other dependencies in the project will continue to use [email protected].
The same applies to other bundlers (like Vite) or libraries/frameworks based on webpack (like father, umi), please search accordingly, we won't elaborate here.
Note that this approach is a temporary transition solution. In the long run, Ant Design v4 version stopped maintenance at the end of 2023, it's recommended to upgrade to [email protected] as soon as possible.
Custom webpack plugin reference:
class AntdV5AliasPlugin {apply(compiler) {compiler.hooks.normalModuleFactory.tap("AntdV5AliasPlugin", (nmf) => {nmf.hooks.beforeResolve.tapAsync("AntdV5AliasPlugin", (resolveData, callback) => {if (resolveData.contextInfo?.issuer?.includes('node_modules/@antv/s2-react-components')) {// Match: "antd" and "antd/es/locale/xxx"if (/antd(\/*)?/.test(resolveData.request)) {// Replace with: "antd-v5" and "antd-v5/es/locale/xxx"resolveData.request = resolveData.request.replace(/antd(\/*)?/,'antd-v5$1')}}callback();});});}}
RowCellonCollapseRowsAll, onLayoutAfterCollapseRows renamed to onRowCellAllCollapsed, onRowCellCollapsed
- <SheetComponent options={s2Options} onCollapseRowsAll={} />+ <SheetComponent options={s2Options} onRowCellAllCollapsed={} />- <SheetComponent options={s2Options} onLayoutAfterCollapseRows={} />+ <SheetComponent options={s2Options} onRowCellCollapsed={} />
onSheetUpdate Renamed to onUpdate, and Added onUpdateAfterRenderonUpdate: Component-level table update event, triggered when data (S2DataConfig) or configuration (S2Options) is updated.onUpdateAfterRender: Component-level table update event, triggered when data (S2DataConfig) or configuration (S2Options) is updated, and after s2.render() is completed.- <SheetComponent onSheetUpdate={} />+ <SheetComponent onUpdate={} onUpdateAfterRender={} />
In version 2.x, if render parameters are not specified in onUpdate, default renderOptions will be used.
<SheetComponentonUpdate={(renderOptions) => {- return renderOptions}}/>
- interface SheetComponentsProps {}+ interface SheetComponentProps {}
@antv/s2-vue is now discontinued. Due to limited resources and considering maintenance costs and package download volume, it will no longer be updated after the 2.0.0 official release. Please encapsulate based on @antv/s2 yourself, or fork the repository for secondary development of community versions.
Please refer to the API Documentation marked with New and Updated for details.
Please read the documentation for more new features and changes. If you encounter any issues during the upgrade process, please provide feedback through GitHub issues or GitHub Discussions. We will respond and improve this document as quickly as possible.