fix(data-table): change default sorter to place null values at the very top or bottom (#5284)

* Update CHANGELOG.en-US.md

* Update CHANGELOG.zh-CN.md

* fix(n-data-table): change default sorter to place null values at the very top or bottom

---------

Co-authored-by: 07akioni <07akioni2@gmail.com>
This commit is contained in:
Vincent 2023-12-20 17:36:32 +01:00 committed by GitHub
parent 7d547a396b
commit b44ffe58d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -110,6 +110,7 @@
- Fix rapid clicks on `n-date-input`'s buttons triggering a text select for the rest of the website.
- Fix `n-auto-complete`'s autocomplete menu's unexpected open when clicking the clear icon with the input not focused, closes [#4658](https://github.com/tusen-ai/naive-ui/issues/4658).
- Fix `n-input`'s `on-keyup` prop type, closes [#5101](https://github.com/tusen-ai/naive-ui/issues/5101)
- Fix `n-data-table`'s default sorter to place null values at the very top or bottom, closes [#5281](https://github.com/tusen-ai/naive-ui/issues/5281).
- Fix `n-popconfirm`'s action button should not be triggered multiple timescloses [#4687](https://github.com/tusen-ai/naive-ui/issues/4687).
### Features

View File

@ -112,6 +112,7 @@
- 修复 `n-date-input` 的按钮快速点击时网站其余文本会被选中
- 修复 `n-auto-complete` 在未聚焦状态下点击清除按钮时补全菜单意外打开的问题,关闭 [#4658](https://github.com/tusen-ai/naive-ui/issues/4658)
- 修复 `n-input` 属性 `on-keyup` 类型,关闭 [#5101](https://github.com/tusen-ai/naive-ui/issues/5101)
- Fix `n-data-table`'s default sorter to place null values at the very top or bottom, closes [#5281](https://github.com/tusen-ai/naive-ui/issues/5281).
- 修复 `n-popconfirm` 操作按钮不应该被多次触发,关闭 [#4687](https://github.com/tusen-ai/naive-ui/issues/4687)
### Features

View File

@ -57,7 +57,11 @@ function getDefaultSorterFn (
const value1 = row1[columnKey]
const value2 = row2[columnKey]
if (typeof value1 === 'number' && typeof value2 === 'number') {
if(value1 === null) {
return -1
} else if(value2 === null) {
return 1
} else if (typeof value1 === 'number' && typeof value2 === 'number') {
return value1 - value2
} else if (typeof value1 === 'string' && typeof value2 === 'string') {
return value1.localeCompare(value2)