Skip to content

Commit

Permalink
feat: array table support sizeChanger (#39)
Browse files Browse the repository at this point in the history
Co-authored-by: xuyongchao <xuyongchao@bytedance.com>
  • Loading branch information
over58 and xuyongchao authored Jun 4, 2024
1 parent e8ed05f commit 378319f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/components/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const ArrayTablePagination: ReactFC<IArrayTablePaginationProps> = (props) => {
const [current, setCurrent] = useState(1)
const prefixCls = usePrefixCls('formily-array-table')
const [wrapSSR, hashId] = useStyle(prefixCls)
const pageSize = props.pageSize || 10
const [pageSize, setPageSize] = useState(props.pageSize || 10)
const size = props.size || 'default'
const dataSource = props.dataSource || []
const startIndex = (current - 1) * pageSize
Expand All @@ -265,6 +265,13 @@ const ArrayTablePagination: ReactFC<IArrayTablePaginationProps> = (props) => {
const handleChange = (current: number) => {
setCurrent(current)
}
const handleSizeChange = (_, size: number) => {
setPageSize(size)
}

useEffect(() => {
setPageSize(props.pageSize || 10)
}, [props.pageSize])

useEffect(() => {
if (totalPage > 0 && totalPage < current) {
Expand All @@ -290,7 +297,8 @@ const ArrayTablePagination: ReactFC<IArrayTablePaginationProps> = (props) => {
current={current}
total={dataSource.length}
size={size}
showSizeChanger={false}
showSizeChanger={true}
onShowSizeChange={handleSizeChange}
onChange={handleChange}
/>
</Space>
Expand Down

0 comments on commit 378319f

Please sign in to comment.