Добавлена обёртка для antd Table с автоподставлением поля key

This commit is contained in:
goodmice 2021-10-15 16:03:09 +05:00
parent 0a0bae2b83
commit d2d6377efd
2 changed files with 12 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import { EditableCell } from './EditableCell'
const newRowKeyValue = 'newRow' const newRowKeyValue = 'newRow'
const tryAddKeys = (items) => { export const tryAddKeys = (items) => {
if(!items?.length || !items[0]) if(!items?.length || !items[0])
return [] return []
if(items[0].key) if(items[0].key)

View File

@ -1,7 +1,8 @@
import { ReactNode } from 'react' import { ReactNode } from 'react'
import { Table as RawTable } from 'antd'
import { tryAddKeys } from './EditableTable'
import { makeNumericSorter, makeStringSorter} from './sorters' import { makeNumericSorter, makeStringSorter} from './sorters'
export { makeDateSorter, makeNumericSorter, makeStringSorter} from './sorters' export { makeDateSorter, makeNumericSorter, makeStringSorter} from './sorters'
export { Table } from 'antd'
export { EditableTable } from './EditableTable' export { EditableTable } from './EditableTable'
export { DatePickerWrapper } from './DatePickerWrapper' export { DatePickerWrapper } from './DatePickerWrapper'
export { SelectFromDictionary } from './SelectFromDictionary' export { SelectFromDictionary } from './SelectFromDictionary'
@ -186,3 +187,12 @@ export const makePaginationObject = (paginationContainer:PaginationContainer, ..
current: page, current: page,
} }
} }
interface TableContainer {
dataSource: any[];
children?: any;
}
export const Table = ({dataSource, children, ...other}: TableContainer) => {
return <RawTable dataSource={tryAddKeys(dataSource)} {...other}>{children}</RawTable>
}