Skip to content

fix: 修复透视表组内排序在指标数据为 null 时排序异常的问题 - #3308

Merged
Alexzjt merged 6 commits into
nextfrom
copilot/fix-issue-3306-bug
Feb 6, 2026
Merged

Alexzjt merged 6 commits into
nextfrom
copilot/fix-issue-3306-bug

Conversation

Copilot AI commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

修复透视表组内排序在指标数据为 null 时排序异常的问题

根据业界最佳实践(Nulls Always Last),修复透视表组内排序功能在指标数据为 null 时的排序问题。

新增 nullsPlacement 配置选项

在 SortParam 中新增 nullsPlacement 配置项,支持用户自定义空值排序位置:

值 说明
'first' 空值永远排在最前
'last' 空值永远排在最后(默认值)
'auto' 升序时空值在前,降序时空值在后

变更说明

  • 在 Sort 接口中添加 nullsPlacement?: NullsPlacement 字段
  • 默认 nullsPlacement='last',无论升序还是降序,空值都排在最后
  • auto 模式:升序时空值在前,降序时空值在后
  • 当用户使用 sortFunc 时,排序逻辑完全由用户控制
  • 更新中英文 API 文档说明(s2-site)
  • 添加测试用例验证 nullsPlacement 选项行为
  • 代码构建成功

使用示例

const s2DataConfig = {
  sortParams: [
    {
      sortFieldId: 'price',
      sortMethod: 'DESC',
      nullsPlacement: 'last', // 空值在最后(默认)
    },
  ],
};

Solve the issue and close #3306

Original prompt

分析issue #3306 是否是本仓库的代码bug,如果是,请进行修复,并解释修复思路。最终提交的PullRequest的标题和描述都应该是中文的。Pull Request的描述中需要包含 Solve the issue and close #3306


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 30, 2026 09:13
Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>
Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>
Copilot AI changed the title [WIP] 修复#3306代码中的bug fix: 修复透视表组内排序在指标数据为 null 时排序异常的问题 Jan 30, 2026
Copilot AI requested a review from Alexzjt January 30, 2026 09:19
@github-actions github-actions Bot added pr(fix) bug fix next 2.0-next 版本的问题 labels Jan 30, 2026
@Alexzjt
Alexzjt marked this pull request as ready for review January 30, 2026 09:22
@codecov-commenter

codecov-commenter commented Jan 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.76471% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.74%. Comparing base (ecdc9c8) to head (056f702).
⚠️ Report is 776 commits behind head on next.

Files with missing lines Patch % Lines
packages/s2-core/src/utils/sort-action.ts 61.76% 2 Missing and 11 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3308      +/-   ##
==========================================
+ Coverage   75.77%   78.74%   +2.97%     
==========================================
  Files         257      224      -33     
  Lines       11994    12448     +454     
  Branches     2464     2817     +353     
==========================================
+ Hits         9088     9802     +714     
+ Misses       1398      945     -453     
- Partials     1508     1701     +193     

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

@github-actions

github-actions Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Size Change: +145 B (+0.02%)

Total Size: 740 kB

Filename Size Change
./packages/s2-core/dist/s2.min.js 308 kB +145 B (+0.05%)
ℹ️ View Unchanged
Filename Size
./packages/s2-core/dist/s2-extends.min.js 207 kB
./packages/s2-core/dist/s2.min.css 581 B
./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

@github-actions

github-actions Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

你好, @Copilot CI 执行失败, 请点击 [Details] 按钮查看, 并根据日志修复。

Hello, @Copilot CI run failed, please click the [Details] button for detailed log information and fix it.

@github-actions github-actions Bot added the 🚨 test failed 单元测试挂了 label Jan 30, 2026
@Alexzjt

Alexzjt commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

@copilot

background

你提到的这种实现逻辑(将 Null 视为最小值/负无穷)在数据库层面(如 MySQL)是常见的,但在面向用户的表格界面(UI/UX)中,这通常不是最佳实践。

业界最佳实践:Nulls Always Last (空值置底)
在 Excel、Google Sheets 以及许多现代 SaaS 数据表格(如 Airtable)中,普遍采用的策略是:无论升序还是降序,Null 值永远排在列表的最后。

优点:

用户关注的是“有数据的项”
不会出现“空值霸榜”
符合 BI / 报表 / 数据分析直觉

action

所以你需要增加一个空值的排序选项

nullsPlacement: 'first' | 'last' | 'auto'
auto:升序 → null 在后 降序 → null 在后
first:永远最前
last:永远最后 (默认)

如果用户自定义了排序函数,则排序函数完全接管
否则:默认:nullsPlacement = 'last'
升降序都不影响 null 位置。

请你顺便在 s2-site 中补充api文档

Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>

Copilot AI commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

background

你提到的这种实现逻辑(将 Null 视为最小值/负无穷)在数据库层面(如 MySQL)是常见的,但在面向用户的表格界面(UI/UX)中,这通�...

已按照业界最佳实践(Nulls Always Last)进行修改,新增 nullsPlacement 配置选项:

nullsPlacement: 'first' | 'last' | 'auto'
  • 'first': 空值永远在最前
  • 'last': 空值永远在最后(默认值)
  • 'auto': 与 'last' 相同,空值始终在后

当用户自定义 sortFunc 时,排序逻辑完全由用户控制,nullsPlacement 不生效。

API 文档已更新:s2-site/common/sort-param.zh.md 和 s2-site/common/sort-param.en.md

提交 commit: 0c077b0

@Alexzjt

Alexzjt commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

@copilot sorry,我前面说错了。auto 的意思是
降序:null值数据在最后
升序:null数据在最前

@github-actions github-actions Bot removed the 🚨 test failed 单元测试挂了 label Jan 30, 2026
Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>

Copilot AI commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot sorry,我前面说错了。auto 的意思是
降序:null值数据在最后
升序:null数据在最前

已修正 auto 的行为:

  • 升序 (ASC): 空值在最前
  • 降序 (DESC): 空值在最后

代码、测试用例和文档已同步更新。

提交 commit: cde958a

@github-actions github-actions Bot added 🚨 test failed 单元测试挂了 and removed 🚨 test failed 单元测试挂了 labels Jan 30, 2026
@github-actions github-actions Bot removed the 🚨 test failed 单元测试挂了 label Jan 31, 2026
@Alexzjt

Alexzjt commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

/gemini review

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

本次 PR 引入了 nullsPlacement 选项来控制排序中的空值行为,这是一个非常实用的功能增强。整体实现很可靠,并且为新功能添加了充分的测试。

我在代码中发现了一些可以改进的地方:

  1. 排序逻辑中存在一个错误,导致在不同情况下对特殊值的处理不一致。
  2. 测试代码中存在一些重复的辅助函数。
  3. 文档中的代码示例有一个微小的格式问题。

修复这些问题将有助于提升代码质量和逻辑的健壮性。整体来看,这是一次很棒的提交!

@Alexzjt
Alexzjt merged commit f02c68a into next Feb 6, 2026
9 checks passed
@Alexzjt
Alexzjt deleted the copilot/fix-issue-3306-bug branch February 6, 2026 05:51
Laffery pushed a commit to Laffery/S2 that referenced this pull request Jul 17, 2026
* Initial plan

* fix: 修复透视表组内排序在指标数据为 null 时排序异常的问题

Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>

* fix: 修复测试用例中 createCellData 函数的类型定义

Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>

* feat: 添加 nullsPlacement 配置项,支持自定义空值排序位置

Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>

* fix: 修正 nullsPlacement='auto' 的行为(升序空值在前,降序空值在后)

Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>

* fix: 提供更完善的全局配置

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Alexzjt <9548248+Alexzjt@users.noreply.github.com>
Co-authored-by: zjt <alex_zjt@163.com>
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.

🐛透视表 某些指标数据为null时, 组内排序功能出现问题

3 participants