Skip to content
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

fix: 修复ArrayTable筛选后, index找寻逻辑错误导致过滤后的数据状态异常 #41

Merged
merged 1 commit into from
Jun 4, 2024
Merged
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
13 changes: 12 additions & 1 deletion docs/components/ArrayTable.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 10 additions & 6 deletions packages/components/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const useArrayTableSources = () => {

return parseArrayItems(schema.items)
}

const indexKey = '__index__'
const useArrayTableColumns = (
dataSource: any[],
field: ArrayField,
Expand All @@ -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
},
})
},
Expand Down Expand Up @@ -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}`)
Expand Down
Loading