Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 修复ArrayTable筛选后, index找寻逻辑错误导致过滤后的数据状态异常
Browse files Browse the repository at this point in the history
xuyongchao committed May 23, 2024
1 parent 705c447 commit 0524624
Showing 2 changed files with 22 additions and 7 deletions.
13 changes: 12 additions & 1 deletion docs/components/ArrayTable.zh-CN.md
Original file line number Diff line number Diff line change
@@ -83,7 +83,18 @@ export default () => {
</SchemaField.Void>
<SchemaField.Void
x-component="ArrayTable.Column"
x-component-props={{ title: 'A2', width: 200 }}
x-component-props={{
title: 'A2',
width: 200,
filters: [
{ text: 'a', value: 'a' },
{ text: 'aa', value: 'aa' },
{ text: 'b', value: 'b' },
],
onFilter(value, record) {
return record.a2 === value
},
}}
>
<SchemaField.String
x-decorator="FormItem"
16 changes: 10 additions & 6 deletions packages/components/src/array-table/index.tsx
Original file line number Diff line number Diff line change
@@ -134,7 +134,7 @@ const useArrayTableSources = () => {

return parseArrayItems(schema.items)
}

const indexKey = '__index__'
const useArrayTableColumns = (
dataSource: any[],
field: ArrayField,
@@ -149,17 +149,19 @@ const useArrayTableColumns = (
key,
dataIndex: name,
render: (value: any, record: any) => {
const index = dataSource.indexOf(record)
const index = record[indexKey]

const children = (
<ArrayBase.Item index={index} record={() => field?.value?.[index]}>
<ArrayBase.Item index={index} record={record}>
<RecursionField
schema={schema}
name={index}
onlyRenderProperties
/>
</ArrayBase.Item>
)
return children

return index > -1 ? children : null
},
})
},
@@ -332,13 +334,15 @@ const InternalArrayTable: ReactFC<TableProps<any>> = observer(
const field = useField<ArrayField>()
const prefixCls = usePrefixCls('formily-array-table')
const [wrapSSR, hashId] = useStyle(prefixCls)
const dataSource = Array.isArray(field.value) ? field.value.slice() : []
const dataSource = Array.isArray(field.value)
? field.value.slice().map((x, idx) => ({ [indexKey]: idx, ...x }))
: []
const sources = useArrayTableSources()
const columns = useArrayTableColumns(dataSource, field, sources)
const pagination = isBool(props.pagination) ? {} : props.pagination
const addition = useAddition()
const defaultRowKey = (record: any) => {
return dataSource.indexOf(record)
return record[indexKey]
}
const addTdStyles = (id: number) => {
const node = ref.current?.querySelector(`.${prefixCls}-row-${id}`)

0 comments on commit 0524624

Please sign in to comment.