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

Customize Order

Previous
Customize Cell Size
Next
Custom Collapse/Expand Nodes

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

Although, S2 tables have default sort operations and advanced sort functionality in React Header component.

But in some business scenarios, we still need custom sorting, which we divide into three parts: custom sorting icon , custom sorting tooltip , and custom sorting operations . Next, I will take you to realize the custom sorting function as shown in the 👇 animation.

custom sort

custom sort icon

Related chapters: custom icon

configuration

  • Close the default icon
const s2Options = {
// 关闭默认 icon
showDefaultHeaderActionIcon: false,
...
}
  • Configure custom icon
const s2Options = {
// 自定义 icon
customSVGIcons: [
{
name: 'customKingIcon',
src: 'https://gw.alipayobjects.com/zos/bmw-prod/f44eb1f5-7cea-45df-875e-76e825a6e0ab.svg',
},
],
...
}
  • Configure icon placement
const s2Options = {
// 配置 icon 展示位置
headerActionIcons: [
{
// 选择 icon, 可以是 S2 自带的,也可以是自定义的 icon
icons: [ 'customKingIcon' ],
// 通过 belongsCell + displayCondition 设置 icon 的展示位置
belongsCell: 'colCell',
displayCondition: (meta) => meta.level === 2,
...
}],
...
}

Show results

beforeafter
beforeafter

custom tooltip

Related chapters: headerActionIcons configuration instructions

configuration

  • Confirm tooltip is open
const s2Options = {
tooltip: {
enable: true,
},
...
}
  • Customize the tooltip display after the icon is clicked
const items = [
{ key: SortMethodType.none, label: '不排序' },
{ key: SortMethodType.asc, label: '升序', icon: 'GroupAsc' },
{ key: SortMethodType.desc, label: '降序', icon: 'GroupDesc' },
{ key: SortMethodType.custom, label: '自定义排序', icon: 'Trend' },
];
const s2Options = {
// 设置自定义 `icon` 的展示条件
headerActionIcons: [
{
// 选择 icon, 可以是 S2 自带的,也可以是自定义的 icon
icons: [ 'customKingIcon' ],
// 通过 belongsCell + displayCondition 设置 icon 的展示位置
belongsCell: 'colCell',
displayCondition: (meta) => meta.level === 2,
// icon 点击之后的执行函数
onClick: (props) => {
const { meta, event } = props;
const operator = {
// 配置 tooltip 中展示的内容
menu: {
items
},
};
// 自定义 tooltip 配置,展示 toolTip
meta.spreadsheet.showTooltipWithInfo(event, [], {
operator,
onlyShowCellText: true,
onlyShowOperator: true,
});
},
},
],
...
}

Display of results

beforeafter
beforeafter

custom sort operation

Related chapter: Custom sorting

configuration

// 执行自定义排序回调
const handleSortCallback = (meta, key) => {
if (key === SortMethodType.custom) {
const sortParams = [
{ sortFieldId: 'type', sortBy: [ '办公用品', '家具' ] },
{ sortFieldId: 'city', sortMethod: 'ASC' },
];
setSortParams(sortParams)
console.log('可以在这里实现你手动排序的交互和逻辑哟', sortParams)
} else {
// 使用 S2 提供的组内排序方式
meta.spreadsheet.groupSortByMethod(key, meta)
;
}
}
const s2Options = {
// 设置自定义 `icon` 的展示条件
headerActionIcons: [
{
onClick: (props) => {
const { meta, event } = props;
const operator = {
onClick: ({ key }) => {
// 执行自定义排序回调
handleSortCallback(meta, key);
meta.spreadsheet.hideTooltip();
},
menu: {
items
},
};
meta.spreadsheet.showTooltipWithInfo(event, [], {
operator,
onlyShowCellText: true,
onlyShowOperator: true,
});
},
...
}
],
...
}

Display of results

Click Custom Sort, and the table will be displayed according to the sort we set.

Categories are manually sorted: [Office Supplies, Furniture], cities 🏙 are arranged in groups in ascending alphabetical order.

after