Skip to content

Commit

Permalink
feat(array-table): 支持pagination为false时分页不显示 (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: feixiang.zhang <[email protected]>
  • Loading branch information
fisher-zh and feixiang.zhang authored Sep 25, 2024
1 parent 6b7daf8 commit 2f67bd2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/components/src/array-table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface ObservableColumnSource {
}
interface IArrayTablePaginationProps extends PaginationProps {
dataSource?: any[]
showPagination: boolean
children?: (
dataSource: any[],
pagination: React.ReactNode,
Expand Down Expand Up @@ -262,6 +263,7 @@ const ArrayTablePagination: ReactFC<IArrayTablePaginationProps> = (props) => {
const [pageSize, setPageSize] = useState(props.pageSize || 10)
const size = props.size || 'default'
const dataSource = props.dataSource || []
const showPagination = props.showPagination
const startIndex = (current - 1) * pageSize
const endIndex = startIndex + pageSize - 1
const total = dataSource?.length || 0
Expand Down Expand Up @@ -291,7 +293,7 @@ const ArrayTablePagination: ReactFC<IArrayTablePaginationProps> = (props) => {
}, [totalPage, current])

const renderPagination = () => {
if (totalPage <= 1) return
if (!showPagination || totalPage <= 1) return
return (
<div className={cls(`${prefixCls}-pagination`, hashId)}>
<Space>
Expand Down Expand Up @@ -323,7 +325,9 @@ const ArrayTablePagination: ReactFC<IArrayTablePaginationProps> = (props) => {
value={{ totalPage, pageSize, startIndex, changePage: handleChange }}
>
{props.children?.(
dataSource?.slice(startIndex, endIndex + 1),
showPagination
? dataSource?.slice(startIndex, endIndex + 1)
: dataSource,
renderPagination(),
{
startIndex,
Expand Down Expand Up @@ -402,13 +406,18 @@ const InternalArrayTable: ReactFC<TableProps<any>> = observer(
const sources = useArrayTableSources()
const columns = useArrayTableColumns(dataSource, field, sources)
const pagination = isBool(props.pagination) ? {} : props.pagination
const showPagination = isBool(props.pagination) ? props.pagination : true
const addition = useAddition()
const defaultRowKey = (record: any) => {
return record[indexKey]
}

return wrapSSR(
<ArrayTablePagination {...pagination} dataSource={dataSource}>
<ArrayTablePagination
{...pagination}
dataSource={dataSource}
showPagination={showPagination}
>
{(dataSource, pager, { startIndex }) => {
return (
<div ref={ref} className={cls(prefixCls, hashId)}>
Expand Down

0 comments on commit 2f67bd2

Please sign in to comment.