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

Hide Columns

Previous
Custom Interaction
Next
Cell Resize

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

When you want to reduce the interference of unimportant information, you can hide the column header so that you can view the data more intuitively. There are three ways to hide the column header

1. Manual Hide - by clicking

Click the column header and click the隐藏button in the pop-up tooltip

preview

Turn off interactive hiding

const s2Options = {
tooltip: {
operation: {
hiddenColumns: false,
},
},
}

2. Autohide - via configuration

Configurable default hidden column headers, pivot tables and schedules

1. Schedule

There is no multi-column header in the detailed table, just specify any field in the columns of fields

const s2DataConfig = {
fields: {
columns: ['province', 'city', 'type', 'price'],
},
};
const s2Options = {
interaction: {
hiddenColumnFields: ['city']
}
}

preview

2. Pivot table

There are multiple column headers in the pivot table, and the node id corresponding to the column header needs to be specified

How to get column header Id?
 // /docs/api/basic-class/spreadsheet
const s2 = new PivotSheet()
console.log(s2.facet.getColCellNodes())
const s2DataConfig = {
fields: {
rows: [
'province',
'city'
],
columns: [
'type',
'sub_type'
],
values: [
'number'
],
valueInCols: true
},
}
const s2Options = {
interaction: {
hiddenColumnFields: ['root[&]家具[&]沙发[&]number'],
}
}

preview

hiddenColumnFields support automatic grouping, for example, hidden is province , type , price

const s2Options = {
interaction: {
hiddenColumnFields: ['province', 'type', 'price']
}
}

The second column city is not configured to hide, then you will get two groups

  • ['province']
  • ['type', 'price']

In this way, two hidden buttons are rendered, and the buttons work independently. Click the first expand button to expand province , click the second expand button to expand type and price

preview

You can also integrate the analysis component, and realize dynamic hiding of column headers by changing the configuration method. For details, please refer to the analysis component

preview

3. Manual hiding - via instance method

View all APIs
const s2 = new PivotSheet(...)
const hiddenColumnFields = ['province', 'type', 'price']
s2.interaction.hideColumns(hiddenColumnFields)

Get hidden column header data

COL_CELL_EXPANDED and COL_CELL_HIDDEN that can be exposed through S2Event monitor the expansion and hiding of the column header respectively

import { S2Event } from '@antv/s2'
const s2 = new PivotSheet(...);
s2.on(S2Event.COL_CELL_EXPANDED, (cell) => {
console.log('列头展开', cell);
});
s2.on(
S2Event.COL_CELL_HIDDEN,
(currentHiddenColumnsInfo, hiddenColumnsDetail) => {
console.log('列头隐藏', currentHiddenColumnsInfo, hiddenColumnsDetail);
},
);

You can also access the hiddenColumnsDetail stored in the store to actively obtain

const hiddenColumnsDetail = s2.store.get('hiddenColumnsDetail')
console.log(hiddenColumnsDetail)