Skip to content

Commit d5ecd93

Browse files
committed
fix(components): fix #3793 arraytable sortable error
1 parent 8f5ead6 commit d5ecd93

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

packages/components/src/array-table/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
useFieldSchema,
1919
RecursionField,
2020
} from "@formily/react";
21-
import { isArr, isBool } from "@formily/shared";
21+
import { isArr, isBool, uid } from "@formily/shared";
2222
import { Schema } from "@formily/json-schema";
2323

2424
import "./index.scss";
@@ -333,13 +333,11 @@ export const ArrayTable: ComposedArrayTable = observer(
333333
const columns = useArrayTableColumns(dataSource, sources);
334334
const pagination = isBool(props.pagination) ? {} : props.pagination;
335335
const addition = useAddition();
336-
const defaultRowKey = (record?: any) => {
337-
return dataSource.indexOf(record).toString();
338-
};
336+
const defaultRowKey = () => uid().toString();
339337

340338
return (
341339
<ArrayTablePagination {...pagination} dataSource={dataSource}>
342-
{(dataSource, pager) => (
340+
{(innerDataSource, pager) => (
343341
<div ref={ref} className={prefixCls}>
344342
<ArrayBase {...props?.arrayBaseProps}>
345343
<ArrayTableComponentsContext.Provider value={{ ref, field }}>
@@ -351,10 +349,10 @@ export const ArrayTable: ComposedArrayTable = observer(
351349
onChange={() => {}}
352350
pagination={false}
353351
columns={columns}
354-
dataSource={dataSource}
352+
dataSource={innerDataSource}
355353
components={arrayTableComponents}
356-
onRow={(_, index) => ({
357-
index,
354+
onRow={(record) => ({
355+
index: dataSource.indexOf(record),
358356
})}
359357
/>
360358
</ArrayTableComponentsContext.Provider>

0 commit comments

Comments
 (0)