Skip to content

fix: 明细表导出序号列 formatter 不生效#3333

Merged
Alexzjt merged 1 commit intonextfrom
fix/3332
Mar 24, 2026
Merged

fix: 明细表导出序号列 formatter 不生效#3333
Alexzjt merged 1 commit intonextfrom
fix/3332

Conversation

@Alexzjt
Copy link
Contributor

@Alexzjt Alexzjt commented Mar 24, 2026

👀 PR includes

🐛 Bugfix

🔧 Chore

  • Test case
  • Docs / demos update
  • CI / workflow
  • Release version
  • Other ()

📝 Description

Issue #3332:明细表使用 asyncGetAllPlainData 导出数据时,序号列(SERIES_NUMBER_FIELD)配置的 meta.formatter 不生效。表格渲染中 formatter 正常工作(显示 a, b, c),但导出结果仍为原始数字(1, 2, 3)。

🖼️ Screenshot

Before After
iShot_2026-03-24_16 52 16 iShot_2026-03-24_16 51 32

🔍 Self-Check before the merge

  • Add or update relevant docs.
  • Add or update relevant demos.
  • Add or update test case.
  • Add or update relevant TypeScript definitions.

@github-actions github-actions bot added the pr(fix) bug fix label Mar 24, 2026
@github-actions
Copy link
Contributor

你好 @Alexzjt,非常感谢你的贡献.
为了让代码更健壮, 请根据 贡献指南 补充相应单元测试 (文档改动或其他特殊场景除外), 如果有 API 改动, 请修改 相应的文档.
同时请检查 linttest 相关 CI 是否通过, 如果失败, 请点击 [Details] 按钮查看, 并根据日志修复.

Hello, @Alexzjt, Thanks for your contribution. In order to make the code more robust, please add the corresponding unit tests, and update the docs if there are API changes.
At the same time, please check whether the CI related to lint and test passes. If the CI fails, please click [Details] button to check and repair according to the log.

@github-actions github-actions bot added the next 2.0-next 版本的问题 label Mar 24, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求解决了一个关键的导出问题,即明细表中的序号列在导出数据时未能正确应用其配置的格式化函数。通过修改数据单元格复制逻辑,现在可以确保无论是在表格显示还是数据导出时,序号列的格式都保持一致,从而提升了数据导出的准确性和用户体验。

Highlights

  • 修复明细表导出问题: 解决了明细表在导出数据时,序号列(SERIES_NUMBER_FIELD)配置的 meta.formatter 不生效的问题。
  • 确保格式化一致性: 现在可以确保在数据导出时,序号列能够正确应用配置的格式化函数,使导出结果与表格显示保持一致。
  • 新增测试用例: 添加了新的测试用例,验证了序号列在同步和异步导出时都能正确格式化,并且在 formatOptionsfalse 时保持原始数字。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次 PR 修复了明细表导出时序号列格式化不生效的问题。通过在 getDataMatrixgetDataMatrixRIC 方法中为序号列应用 formatter,解决了该问题。同时添加了完整的单元测试,覆盖了同步、异步以及禁用格式化的场景。代码修改是正确的,并且测试用例很完善。我只提出了一个关于代码重复的小建议,以提高可维护性。

@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.67%. Comparing base (ecdc9c8) to head (5c52c18).
⚠️ Report is 794 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3333      +/-   ##
==========================================
+ Coverage   75.77%   78.67%   +2.90%     
==========================================
  Files         257      224      -33     
  Lines       11994    12489     +495     
  Branches     2464     2836     +372     
==========================================
+ Hits         9088     9826     +738     
+ Misses       1398      956     -442     
- Partials     1508     1707     +199     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Alexzjt
Copy link
Contributor Author

Alexzjt commented Mar 24, 2026

/**
 * Issue #3332 最小复现:明细表导出不支持序号的格式化
 * https://github.com/antvis/S2/issues/3332
 *
 * 问题:使用 asyncGetAllPlainData 导出明细表数据时,
 * 序号列(SERIES_NUMBER_FIELD)的 meta formatter 不生效。
 * 期望序号按 formatter 格式化导出(如 a, b, c),但实际导出的是原始数字。
 */
import {
  SERIES_NUMBER_FIELD,
  SpreadSheet,
  asyncGetAllPlainData,
  type S2DataConfig,
} from '@antv/s2';
import React, { useRef } from 'react';
import { createRoot } from 'react-dom/client';
import { SheetComponent, type SheetComponentOptions } from '../src';

const s2DataConfig: S2DataConfig = {
  fields: {
    columns: ['province', 'city', 'type', 'price'],
  },
  meta: [
    {
      field: SERIES_NUMBER_FIELD,
      name: '序号',
      formatter: (value) => {
        // 将数字序号转换为字母:1->a, 2->b, 3->c ...
        return String.fromCharCode(96 + Number(value));
      },
    },
  ],
  data: [
    { province: '浙江', city: '杭州', type: '笔', price: 1 },
    { province: '浙江', city: '宁波', type: '纸', price: 2 },
    { province: '江苏', city: '南京', type: '笔', price: 5 },
    { province: '江苏', city: '苏州', type: '纸', price: 3 },
    { province: '广东', city: '广州', type: '笔', price: 4 },
  ],
};

const s2Options: SheetComponentOptions = {
  width: 600,
  height: 480,
  seriesNumber: {
    enable: true,
  },
};

function App() {
  const s2Ref = useRef<SpreadSheet>(null);

  const handleExport = async () => {
    if (!s2Ref.current) {
      return;
    }

    const csv = await asyncGetAllPlainData({
      sheetInstance: s2Ref.current,
      split: ',',
      formatOptions: true,
    });

    console.log('导出结果:\n', csv);
  };

  return (
    <div style={{ padding: 16 }}>
      <h3>Issue #3332: 明细表导出不支持序号的格式化</h3>
      <p>
        表格中序号列显示为 a, b, c(formatter 生效),
        但点击导出后控制台打印的序号仍为原始数字 1, 2, 3
      </p>
      <button
        onClick={handleExport}
        style={{ marginBottom: 12, padding: '6px 16px', cursor: 'pointer' }}
      >
        导出数据(查看控制台)
      </button>
      <SheetComponent
        sheetType="table"
        dataCfg={s2DataConfig}
        options={s2Options}
        ref={s2Ref}
      />
    </div>
  );
}

createRoot(document.getElementById('root')!).render(<App />);

@github-actions
Copy link
Contributor

Size Change: +24 B (0%)

Total Size: 744 kB

Filename Size Change
./packages/s2-core/dist/s2-extends.min.js 209 kB +14 B (+0.01%)
./packages/s2-core/dist/s2.min.css 581 B -2 B (-0.34%)
./packages/s2-core/dist/s2.min.js 311 kB +12 B (0%)
ℹ️ View Unchanged
Filename Size
./packages/s2-react-components/dist/s2-react-components.min.css 2.55 kB
./packages/s2-react-components/dist/s2-react-components.min.js 123 kB
./packages/s2-react/dist/s2-react.min.css 1.3 kB
./packages/s2-react/dist/s2-react.min.js 38.5 kB
./packages/s2-vue/dist/s2-vue.min.css 3.8 kB
./packages/s2-vue/dist/s2-vue.min.js 54.2 kB

compressed-size-action

@Alexzjt Alexzjt merged commit 4a333c3 into next Mar 24, 2026
14 checks passed
@Alexzjt Alexzjt deleted the fix/3332 branch March 24, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next 2.0-next 版本的问题 pr(fix) bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 明细表导出不支持序号的格式化

3 participants