From 044e2e4e866dd5b120daab03c47aba1ca1f9140a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Mon, 6 Sep 2021 20:12:48 +0800 Subject: [PATCH] fix(table): `rowClassName` not worked with `striped` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复rowClassName属性无法和striped同时生效的问题 fixed: #1167 --- CHANGELOG.zh_CN.md | 1 + src/components/Table/src/hooks/useTableStyle.ts | 9 ++++++--- src/components/Table/src/types/table.ts | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.zh_CN.md b/CHANGELOG.zh_CN.md index a297bdb7..54142c3b 100644 --- a/CHANGELOG.zh_CN.md +++ b/CHANGELOG.zh_CN.md @@ -4,6 +4,7 @@ - **BasicTable** - 单元格编辑新增提交回调,将根据回调函数返回的结果来决定是否将数据提交到表格 - 行编辑添加校验方法,允许只校验而不提交值,以便异步保存数据成功后才提交倒表格 + - 修复`rowClassName`属性无法和`striped`同时使用的问题 ### 🐛 Bug Fixes diff --git a/src/components/Table/src/hooks/useTableStyle.ts b/src/components/Table/src/hooks/useTableStyle.ts index 77783e6f..292187d8 100644 --- a/src/components/Table/src/hooks/useTableStyle.ts +++ b/src/components/Table/src/hooks/useTableStyle.ts @@ -6,11 +6,14 @@ import { isFunction } from '/@/utils/is'; export function useTableStyle(propsRef: ComputedRef, prefixCls: string) { function getRowClassName(record: TableCustomRecord, index: number) { const { striped, rowClassName } = unref(propsRef); - if (!striped) return; + const classNames: string[] = []; + if (striped) { + classNames.push((index || 0) % 2 === 1 ? `${prefixCls}-row__striped` : ''); + } if (rowClassName && isFunction(rowClassName)) { - return rowClassName(record); + classNames.push(rowClassName(record, index)); } - return (index || 0) % 2 === 1 ? `${prefixCls}-row__striped` : ''; + return classNames.filter((cls) => !!cls).join(' '); } return { getRowClassName }; diff --git a/src/components/Table/src/types/table.ts b/src/components/Table/src/types/table.ts index 7660b0fc..f9df66cf 100644 --- a/src/components/Table/src/types/table.ts +++ b/src/components/Table/src/types/table.ts @@ -25,7 +25,7 @@ export interface TableRowSelection extends ITableRowSelection { /** * Callback executed when select/deselect one row - * @type FunctionT + * @type Function */ onSelect?: (record: T, selected: boolean, selectedRows: Object[], nativeEvent: Event) => any; @@ -291,7 +291,7 @@ export interface BasicTableProps { * Row's className * @type Function */ - rowClassName?: (record: TableCustomRecord) => string; + rowClassName?: (record: TableCustomRecord, index: number) => string; /** * Row selection config -- GitLab