Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #1752 #1753

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
- 修复 `Table` 组件表头分组中使用 fixedToColumn 属性导致表头错乱 [#1732](https://github.com/XiaoMi/hiui/issues/1732)
- 修复 `Upload` 组件 onRemove 回调 api 导致外部引用闭包的问题 [#1739](https://github.com/XiaoMi/hiui/issues/1739)
- 修复 `Form` 组件 Form.Item 子节点 onChange 方法中设置表单值异常问题 [#1745](https://github.com/XiaoMi/hiui/issues/1745)
- 修复 `Table` 组件 批量选择形态中,在 data 为空数组时,表头全选项会默认勾选 [#1749](https://github.com/XiaoMi/hiui/issues/1749)
- 修复 `Table` 组件 批量选择形态中,在 data 为空数组时,表头全选项会默认勾选问题 [#1749](https://github.com/XiaoMi/hiui/issues/1749)
- 修复 `Table` 组件 批量选择形态中,表格禁用行,全选时会被勾选问题 [#1752](https://github.com/XiaoMi/hiui/issues/1752)

# 3.6.1
- 修复部分组件 'regeneratorRuntime is not defined' 问题 [#1719](https://github.com/XiaoMi/hiui/issues/1719)
- 修复 `Slider` max 和min 受控问题 [#1703](https://github.com/XiaoMi/hiui/issues/1703)
Expand Down
16 changes: 13 additions & 3 deletions components/table/HeaderTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const HeaderTable = ({ isFixed, bodyWidth, rightFixedIndex }) => {
scrollWidth,
eachHeaderHeight,
setEachHeaderHeight,
onHeaderRow
onHeaderRow,
disabledData
} = useContext(TableContext)

// ******************** 隐藏滚动条
Expand All @@ -54,7 +55,10 @@ const HeaderTable = ({ isFixed, bodyWidth, rightFixedIndex }) => {
if (rowSelection) {
const { selectedRowKeys = [] } = rowSelection
const flattedData = flatTreeData(data)
isAllChecked = flattedData.every((d) => selectedRowKeys.includes(d.key)) && flattedData.length !== 0
isAllChecked =
flattedData
.filter((data) => !disabledData.current.includes(data.key))
.every((d) => selectedRowKeys.includes(d.key)) && flattedData.length !== 0
}
// *********************

Expand Down Expand Up @@ -152,7 +156,13 @@ const HeaderTable = ({ isFixed, bodyWidth, rightFixedIndex }) => {
indeterminate={!isAllChecked && rowSelection.selectedRowKeys.length > 0}
onChange={(e) => {
if (rowSelection.onChange) {
rowSelection.onChange(isAllChecked ? [] : flatTreeData(data).map((d) => d.key))
rowSelection.onChange(
isAllChecked
? []
: flatTreeData(data)
.filter((data) => !disabledData.current.includes(data.key))
.map((d) => d.key)
)
}
}}
/>
Expand Down
4 changes: 3 additions & 1 deletion components/table/Row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const Row = ({
rowExpandable,
onExpand,
flatLeftFixedColumns,
flatRightFixedColumns
flatRightFixedColumns,
disabledData
} = useContext(TableContext)

const _columns = _.cloneDeep(columns)
Expand All @@ -60,6 +61,7 @@ const Row = ({
}
const checkboxConfig = rowSelection && rowSelection.getCheckboxConfig && rowSelection.getCheckboxConfig(allRowData)
const checkboxDisabled = (checkboxConfig && checkboxConfig.disabled) || false
checkboxDisabled && disabledData.current.push(allRowData.key)
const rowExpand = rowExpandable && rowExpandable(rowData)
return [
<tr
Expand Down
3 changes: 3 additions & 0 deletions components/table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const Table = ({
emptyContent = localeDatas.table.emptyContent
}) => {
const hiTable = useRef(null)
const disabledData = useRef([])
const [ceiling, setCeiling] = useState(false)
const [activeSorterColumn, setActiveSorterColumn] = useState(null)
const [activeSorterType, setActiveSorterType] = useState(null)
Expand All @@ -77,6 +78,7 @@ const Table = ({
const firstRowRef = useRef(null)

useEffect(() => {
disabledData.current = []
if (!dataSource) {
if (firstRowRef.current) {
const _realColumnsWidth = Array.from(firstRowRef.current.childNodes).map((node) => node.clientWidth)
Expand Down Expand Up @@ -177,6 +179,7 @@ const Table = ({
return (
<TableContext.Provider
value={{
disabledData,
rowExpandable,
setting,
firstRowRef,
Expand Down