mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 03:46:08 +00:00
fix: pagination issue in list block with simple pagination collection (#5500)
This commit is contained in:
parent
8e6da46691
commit
5010a052b5
@ -28,6 +28,7 @@ const InternalList = (props) => {
|
|||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const Designer = useDesigner();
|
const Designer = useDesigner();
|
||||||
const meta = service?.data?.meta;
|
const meta = service?.data?.meta;
|
||||||
|
const { pageSize, count, hasNext, page } = meta || {};
|
||||||
const field = useField<ArrayField>();
|
const field = useField<ArrayField>();
|
||||||
const [schemaMap] = useState(new Map());
|
const [schemaMap] = useState(new Map());
|
||||||
const { wrapSSR, componentCls, hashId } = useStyles();
|
const { wrapSSR, componentCls, hashId } = useStyles();
|
||||||
@ -63,7 +64,51 @@ const InternalList = (props) => {
|
|||||||
},
|
},
|
||||||
[run, params],
|
[run, params],
|
||||||
);
|
);
|
||||||
|
const usePagination = () => {
|
||||||
|
if (!count) {
|
||||||
|
return {
|
||||||
|
onChange: onPaginationChange,
|
||||||
|
total: count || field.value?.length < pageSize || !hasNext ? pageSize * page : pageSize * page + 1,
|
||||||
|
pageSize: pageSize || 10,
|
||||||
|
current: page || 1,
|
||||||
|
showSizeChanger: true,
|
||||||
|
pageSizeOptions,
|
||||||
|
simple: true,
|
||||||
|
className: css`
|
||||||
|
.ant-pagination-simple-pager {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
itemRender: (_, type, originalElement) => {
|
||||||
|
if (type === 'prev') {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{ display: 'flex' }}
|
||||||
|
className={css`
|
||||||
|
.ant-pagination-item-link {
|
||||||
|
min-width: ${token.controlHeight}px;
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
{originalElement} <div style={{ marginLeft: '7px' }}>{page}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return originalElement;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
onChange: onPaginationChange,
|
||||||
|
total: count || 0,
|
||||||
|
pageSize: pageSize || 10,
|
||||||
|
current: page || 1,
|
||||||
|
showSizeChanger: true,
|
||||||
|
pageSizeOptions,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const paginationProps = usePagination();
|
||||||
return wrapSSR(
|
return wrapSSR(
|
||||||
<SchemaComponentOptions
|
<SchemaComponentOptions
|
||||||
scope={{
|
scope={{
|
||||||
@ -91,18 +136,7 @@ const InternalList = (props) => {
|
|||||||
<div className="nb-list-container">
|
<div className="nb-list-container">
|
||||||
<AntdList
|
<AntdList
|
||||||
{...props}
|
{...props}
|
||||||
pagination={
|
pagination={!meta || !field.value?.length ? false : paginationProps}
|
||||||
!meta || !field.value?.length
|
|
||||||
? false
|
|
||||||
: {
|
|
||||||
onChange: onPaginationChange,
|
|
||||||
total: meta?.count || 0,
|
|
||||||
pageSize: meta?.pageSize || 10,
|
|
||||||
current: meta?.page || 1,
|
|
||||||
showSizeChanger: true,
|
|
||||||
pageSizeOptions,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loading={service?.loading}
|
loading={service?.loading}
|
||||||
>
|
>
|
||||||
{field.value?.length
|
{field.value?.length
|
||||||
|
Loading…
Reference in New Issue
Block a user