Skip to content

Commit

Permalink
fix: customRender
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jul 8, 2024
1 parent b815184 commit 2050fb7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/packages/table/__tests__/Table.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ describe('Table', () => {
children: [
{
title: 'Title 6-1',
customRender: (value, row) => {
return row.demo6
customRender: ({ record }) => {
return record.demo6
}
}
]
Expand Down
16 changes: 10 additions & 6 deletions src/packages/table/editable-table/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent, reactive, watch } from 'vue'
import { Field, Form } from '@/packages/form'
import Table from '../table'
import { pick } from 'lodash-es'
import { omit, pick } from 'lodash-es'

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

function customRender (text, record, index, column) {
function onValidate (name, status, errors) {
console.log(name, status, errors)
}

function customRender ({ text, record, index, column }) {
const { fieldProps, formItemProps } = column
const namePath = column.key || column.dataIndex

const needFormItemProps = {
...formItemProps,
name: [index, namePath]
// label: column.title
...omit(formItemProps, ['label']),
name: [index, namePath],
noStyle: true
}
const needFieldProps = {
...pick(column, Object.keys(Field.props)),
Expand All @@ -70,7 +74,7 @@ export default defineComponent({
toolbar: false
}
return (
<Form model={model} layout={'vertical'}>
<Form model={model} onValidate={onValidate} layout={'vertical'}>
<Table {...tableProps}/>
</Form>
)
Expand Down
4 changes: 2 additions & 2 deletions src/packages/table/hooks/useCustomRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function getCopyable (column, text) {
}

function customRender (oldColumn, emptyText) {
return function ({ text, record, index, column }) {
return function ({ text, ...restArgs }) {
if (oldColumn.customRender && isFunction(oldColumn.customRender)) {
const oldCustomRender = oldColumn.customRender
return oldCustomRender.apply(null, [text, record, index, column])
return oldCustomRender.call(null, { text, ...restArgs })
}
if (oldColumn.valueEnum && isObject(oldColumn.valueEnum) && !isEmpty(text)) {
return valueEnumToText(text, oldColumn.valueEnum)
Expand Down

0 comments on commit 2050fb7

Please sign in to comment.