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

Totals

Previous
Conditions
Next
Custom Sort

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...

Introduction

Subtotals belong to the pivot function of the table, and subtotals can be configured for rows and columns.

Subtotal

Aggregate Measures for a Dimension

Form 1: adding extra rows/columns

In tile mode, add an extra row/column to the current dimension

row

Form 2: Affiliate Node

In tree mode, anchor to the row/column where the current node is located

row

total

Aggregate measures across all dimensions, additional rows/columns are required for both tiled and treed modes

1. Single measure

Tile:

row

Tree:

row

2. Multiple metrics

Tile:

row

Tree:

row

use

1. Display configuration

Configure the totals attribute of S2Options to realize whether to display the row and column subtotals and the display position. The types are as follows:

Totals

object is required , default: null Function description: subtotal total configuration

parameterillustratetypeDefaultsrequired
rowcolumn totalTotal{}
colrow totalTotal{}

Total

object is required , default: null Function description: Subtotal calculation configuration

parameterillustratetypeDefaultsrequired
showGrandTotalsWhether to display the totalbooleanfalse✓
showSubTotalsWhether to display subtotals. When configured as an object, always controls whether to always display subtotals when there are less than 2 subdimensions, and does not display by default.`boolean{ always: boolean }`false
subTotalsDimensionsSummary Dimensions for Subtotalsstring[][]✓
reverseGrandTotalsLayouttotal layout position, default bottom or rightbooleanfalse✓
reverseSubTotalsLayoutSubtotal layout position, default bottom or rightbooleanfalse✓
labeltotal aliasstring
subLabelsubtotal aliasstring
calcGrandTotalscalculate the totalCalcTotals
calcSubTotalscalculate subtotalCalcTotals
const s2Options = {
totals: {
row: {
showGrandTotals: true,
showSubTotals: true,
reverseGrandTotalsLayout: true,
reverseSubTotalsLayout: true,
subTotalsDimensions: ['province'],
},
col: {
showGrandTotals: true,
showSubTotals: true,
reverseGrandTotalsLayout: true,
reverseSubTotalsLayout: true,
subTotalsDimensions: ['type'],
},
},
};

2. Data

1. Data incoming

The data is imported according to the row/column position and key value, and the dimension key value does not include the keys of all rows and columns, for example:

[
// 总计/总计
{
price: '15.5',
},
// 浙江/总计
{
province: '浙江',
price: '5.5',
},
// 浙江-杭州/总计
{
province: '浙江',
city: '杭州',
price: '3',
},
// 总计/笔
{
type: '笔',
price: '10',
},
// 浙江-小计/笔
{
province: "浙江",
type: "笔",
price: "3"
},
]
Collect the total and subtotal data into data
const s2DataConfig = {
data: [
{
province: '浙江',
city: '杭州',
type: '笔',
price: '1',
},
// 总计/总计
{
price: '15.5',
},
],
...
};

2. Calculate the data

You can configure attributes calcGrandTotals and calcSubTotals for row and col under totals respectively to realize the calculation of summary data

1. Configure aggregation mode

It is realized by configuring aggregation , which currently supports SUM (sum), MIN (minimum value), MAX (maximum value) , AVG (arithmetic average) and COUNT.

const s2Options = {
totals: {
row: {
showGrandTotals: true,
showSubTotals: true,
reverseGrandTotalsLayout: true,
reverseSubTotalsLayout: true,
subTotalsDimensions: ['province'],
calcGrandTotals: {
aggregation: 'SUM',
},
calcSubTotals: {
aggregation: 'SUM',
},
},
col: {
showGrandTotals: true,
showSubTotals: true,
reverseGrandTotalsLayout: true,
reverseSubTotalsLayout: true,
subTotalsDimensions: ['type'],
calcGrandTotals: {
aggregation: 'SUM',
},
calcSubTotals: {
aggregation: 'SUM',
},
},
},
};
2. Configure custom methods

Realized by configuring calcFunc: (query: Record<string, any>, arr: Record<string, any>[]) => number

const s2Options = {
totals: {
row: {
showGrandTotals: true,
showSubTotals: true,
reverseGrandTotalsLayout: true,
reverseSubTotalsLayout: true,
subTotalsDimensions: ['province'],
calcGrandTotals: {
calcFunc: (query, data) => {},
},
calcSubTotals: {
calcFunc: (query, data) => {},
},
},
col: {
showGrandTotals: true,
showSubTotals: true,
reverseGrandTotalsLayout: true,
reverseSubTotalsLayout: true,
subTotalsDimensions: ['type'],
calcGrandTotals: {
calcFunc: (query, data) => {},
},
calcSubTotals: {
calcFunc: (query, data) => {},
},
},
},
};

priority

  1. Data input priority is higher than calculation data
  2. Configuring custom methods takes precedence over configuring aggregation methods, that is, configuring calcFunc > aggregation
  3. When the same cell is a行+列summary value, the priority is:列总计/列小计> 行总计/行小计