Skip to content

feat(Table): Supple Validate Table Cell Data #3510

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/table/hooks/useEditableRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export default function useRowEdit(props: PrimaryTableProps, context: SetupConte
editableKeysMap,
validateTableData,
validateRowData,
validateTableCellData,
onRuleChange,
clearValidateData,
getEditRowData,
Expand Down
4 changes: 1 addition & 3 deletions src/table/primary-table-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default {
defaultDisplayColumns: {
type: Array as PropType<TdPrimaryTableProps['defaultDisplayColumns']>,
},
/** 拖拽排序方式,值为 `row` 表示行拖拽排序,这种方式无法进行文本复制,慎用。值为`row-handler` 表示通过拖拽手柄进行行拖拽排序。值为 `col` 表示列顺序拖拽。值为 `row-handler-col` 表示同时支持行拖拽和列拖拽。⚠️`drag-col` 已废弃,请勿使用 */
/** 拖拽排序方式,值为 `row` 表示行拖拽排序,这种方式无法进行文本复制,慎用。值为`row-handler` 表示通过拖拽手柄进行行拖拽排序。值为 `col` 表示列顺序拖拽。值为 `row-handler-col` 表示同时支持行拖拽和列拖拽。⚠️`drag-col` 已废弃,请勿使用 */
dragSort: {
type: String as PropType<TdPrimaryTableProps['dragSort']>,
validator(val: TdPrimaryTableProps['dragSort']): boolean {
Expand Down Expand Up @@ -145,8 +145,6 @@ export default {
sortIcon: {
type: Function as PropType<TdPrimaryTableProps['sortIcon']>,
},
/** 已废弃。允许表格行拖拽时排序。请更为使用 `dragSort=\"row\"` */
sortOnRowDraggable: Boolean,
/** 异步加载区域被点击时触发 */
onAsyncLoadingClick: Function as PropType<TdPrimaryTableProps['onAsyncLoadingClick']>,
/** 单元格点击时触发 */
Expand Down
2 changes: 2 additions & 0 deletions src/table/primary-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default defineComponent({
editableKeysMap,
validateRowData,
validateTableData,
validateTableCellData,
onRuleChange,
clearValidateData,
getEditRowData,
Expand Down Expand Up @@ -375,6 +376,7 @@ export default defineComponent({
},
validateRowData,
validateTableData,
validateTableCellData,
clearValidateData,
renderTNode,
renderColumnController,
Expand Down
1 change: 1 addition & 0 deletions src/table/table.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ name | params | return | description
-- | -- | -- | --
clearValidateData | \- | \- | required。clear all validated errors
validateRowData | `(rowValue: any)` | `Promise<{ trigger: TableValidateTrigger, result: ErrorListObjectType<T>[] }>` | required。[see more ts definition](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts)。<br/>`type ErrorListObjectType<T> = PrimaryTableRowEditContext<T> & { errorList: AllValidateResult[] }`<br/>
validateTableCellData | \- | `Promise<{ result: TableErrorListMap }>` | required
validateTableData | \- | `Promise<{ result: TableErrorListMap }>` | required

### PrimaryTableCol
Expand Down
3 changes: 2 additions & 1 deletion src/table/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ onRowEdit | Function | | TS 类型:`(context: PrimaryTableRowEditContext<T>)
onRowValidate | Function | | TS 类型:`(context: PrimaryTableRowValidateContext<T>) => void`<br/>行编辑校验完成后触发,即组件实例方法 `validateRowData` 执行结束后触发。`result` 表示校验结果,`trigger=self` 表示编辑组件内部触发的校验,`trigger='parent'` 表示表格父组件触发的校验。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts)。<br/>`type PrimaryTableRowValidateContext<T> = { result: TableRowValidateResult<T>[]; trigger: TableValidateTrigger }`<br/><br/>`type TableValidateTrigger = 'self' \| 'parent'`<br/><br/>`export type TableRowValidateResult<T> = PrimaryTableCellParams<T> & { errorList: AllValidateResult[]; value: any }`<br/> | N
onSelectChange | Function | | TS 类型:`(selectedRowKeys: Array<string \| number>, options: SelectOptions<T>) => void`<br/>选中行发生变化时触发,泛型 T 指表格数据类型。两个参数,第一个参数为选中行 keys,第二个参数为更多参数,具体如下:`type = uncheck` 表示当前行操作为「取消行选中」;`type = check` 表示当前行操作为「行选中」; `currentRowKey` 表示当前操作行的 rowKey 值; `currentRowData` 表示当前操作行的行数据。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts)。<br/>`interface SelectOptions<T> { selectedRowData: Array<T>; type: 'uncheck' \| 'check'; currentRowKey?: string; currentRowData?: T }`<br/> | N
onSortChange | Function | | TS 类型:`(sort: TableSort, options: SortOptions<T>) => void`<br/>排序发生变化时触发。其中 sortBy 表示当前排序的字段,sortType 表示排序的方式,currentDataSource 表示 sorter 排序后的结果,col 表示列配置。sort 值类型为数组时表示多字段排序。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts)。<br/>`interface SortOptions<T> { currentDataSource?: Array<T>; col: PrimaryTableCol }`<br/> | N
onValidate | Function | | TS 类型:`(context: PrimaryTableValidateContext) => void`<br/>可编辑行表格,全部数据校验完成后触发。即组件实例方法 `validateTableData` 执行结束后触发。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts)。<br/>`interface PrimaryTableValidateContext { result: TableErrorListMap }`<br/><br/>`type TableErrorListMap = { [key: string]: AllValidateResult[] }`<br/> | N
onValidate | Function | | TS 类型:`(context: PrimaryTableValidateContext) => void`<br/>可编辑行表格,全部数据校验完成后触发。即组件实例方法 `validateTableData` 或 `validateTableCellData` 执行结束后触发。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts)。<br/>`interface PrimaryTableValidateContext { result: TableErrorListMap }`<br/><br/>`type TableErrorListMap = { [key: string]: AllValidateResult[] }`<br/> | N

### PrimaryTable Events

Expand Down Expand Up @@ -202,6 +202,7 @@ validate | `(context: PrimaryTableValidateContext)` | 可编辑行表格,全
-- | -- | -- | --
clearValidateData | \- | \- | 必需。清空所有校验结果
validateRowData | `(rowValue: any)` | `Promise<{ trigger: TableValidateTrigger, result: ErrorListObjectType<T>[] }>` | 必需。校验行信息,校验完成后,会触发事件 `onRowValidate`。参数 `rowValue` 表示行唯一标识的值。[详细类型定义](https://github.com/Tencent/tdesign-vue/tree/develop/src/table/type.ts)。<br/>`type ErrorListObjectType<T> = PrimaryTableRowEditContext<T> & { errorList: AllValidateResult[] }`<br/>
validateTableCellData | \- | `Promise<{ result: TableErrorListMap }>` | 必需。校验表格可编辑单元格数据,校验完成后,会触发事件 `onValidate`
validateTableData | \- | `Promise<{ result: TableErrorListMap }>` | 必需。校验表格全部数据,校验完成后,会触发事件 `onValidate`

### PrimaryTableCol
Expand Down
4 changes: 4 additions & 0 deletions src/table/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ export interface PrimaryTableInstanceFunctions<T extends TableRowData = TableRow
* 校验行信息,校验完成后,会触发事件 `onRowValidate`。参数 `rowValue` 表示行唯一标识的值
*/
validateRowData: (rowValue: any) => Promise<{ trigger: TableValidateTrigger; result: ErrorListObjectType<T>[] }>;
/**
* 校验表格可编辑单元格数据,校验完成后,会触发事件 `onValidate`
*/
validateTableCellData: () => Promise<{ result: TableErrorListMap }>;
/**
* 校验表格全部数据,校验完成后,会触发事件 `onValidate`
*/
Expand Down
Loading