Skip to content

Commit 2050fb7

Browse files
author
cole
committed
fix: customRender
1 parent b815184 commit 2050fb7

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/packages/table/__tests__/Table.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ describe('Table', () => {
180180
children: [
181181
{
182182
title: 'Title 6-1',
183-
customRender: (value, row) => {
184-
return row.demo6
183+
customRender: ({ record }) => {
184+
return record.demo6
185185
}
186186
}
187187
]

src/packages/table/editable-table/index.jsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineComponent, reactive, watch } from 'vue'
22
import { Field, Form } from '@/packages/form'
33
import Table from '../table'
4-
import { pick } from 'lodash-es'
4+
import { omit, pick } from 'lodash-es'
55

66
const editable = {
77
type: 'multiple', // 可编辑表格的类型,单行编辑或者多行编辑
@@ -38,14 +38,18 @@ export default defineComponent({
3838
emit('update:value', value)
3939
}, { deep: true, immediate: true })
4040

41-
function customRender (text, record, index, column) {
41+
function onValidate (name, status, errors) {
42+
console.log(name, status, errors)
43+
}
44+
45+
function customRender ({ text, record, index, column }) {
4246
const { fieldProps, formItemProps } = column
4347
const namePath = column.key || column.dataIndex
4448

4549
const needFormItemProps = {
46-
...formItemProps,
47-
name: [index, namePath]
48-
// label: column.title
50+
...omit(formItemProps, ['label']),
51+
name: [index, namePath],
52+
noStyle: true
4953
}
5054
const needFieldProps = {
5155
...pick(column, Object.keys(Field.props)),
@@ -70,7 +74,7 @@ export default defineComponent({
7074
toolbar: false
7175
}
7276
return (
73-
<Form model={model} layout={'vertical'}>
77+
<Form model={model} onValidate={onValidate} layout={'vertical'}>
7478
<Table {...tableProps}/>
7579
</Form>
7680
)

src/packages/table/hooks/useCustomRender.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ function getCopyable (column, text) {
2222
}
2323

2424
function customRender (oldColumn, emptyText) {
25-
return function ({ text, record, index, column }) {
25+
return function ({ text, ...restArgs }) {
2626
if (oldColumn.customRender && isFunction(oldColumn.customRender)) {
2727
const oldCustomRender = oldColumn.customRender
28-
return oldCustomRender.apply(null, [text, record, index, column])
28+
return oldCustomRender.call(null, { text, ...restArgs })
2929
}
3030
if (oldColumn.valueEnum && isObject(oldColumn.valueEnum) && !isEmpty(text)) {
3131
return valueEnumToText(text, oldColumn.valueEnum)

0 commit comments

Comments
 (0)