-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useAntdTable在submit的时候,固定分页条件 #2635
Comments
加了一个标记,通过onChange触发了,下面是proTable const [form] = Form.useForm();
const { tableProps, search: { submit, reset } } = useAntdTable(request, {
defaultPageSize,
form
});
if(tableRef){
useImperativeHandle(tableRef, () => {
return {
submit: (useCurrentPage = false) => {
if (useCurrentPage) {
tableProps.onChange(pagination);
} else {
submit()
}
setSelectedKeys([]);
setSelectedRows([]);
},
reset: () => {
reset();
setSelectedKeys([]);
setSelectedRows([]);
}
}
});
}
...
// 缓存当前的分页信息
const [pagination, setPagination] = useState({ current: 1, pageSize: defaultPageSize });
const handleTableChange = (page:number, pageSize:number) => {
setPagination({current: page, pageSize})
tableProps.onChange({current: page, pageSize})
}
...
<Form form={form}>
<Col
{...searchGrid}
offset={fold && search.length > colNum - 1 ? undefined : notFoldOffset}
>
<Space align="baseline" style={{width: '100%', justifyContent: 'end', marginRight: 16}}>
<Button type="primary" onClick={() => {
setPagination({...pagination, current: 1})
submit();
}}>
查询
</Button>
<Button onClick={() => {
setPagination({current: 1, pageSize: defaultPageSize})
reset();
onReset && onReset();
}}>
重置
</Button>
{search.length > colNum - 1 && (
<a style={{ marginLeft: 8 }} onClick={() => setFold(!fold)}>
{fold ? '展开' : '收起'}
<span>{fold ? <DownOutlined/> : <UpOutlined/>}</span>
</a>
)}
</Space>
</Col>
</Form>
...
<Pagination
showQuickJumper
showTotal={(total) => `总共 ${total} 条`}
pageSizeOptions={Array.from({ length: 10 }, (_, i) => (i + 1) * 10).map(String)}
{...tableProps.pagination}
onChange={(page, pageSize) => handleTableChange(page, pageSize)}
/>
... 外部掉用 // 启用、禁用
const handleEnable = async (record: Auth.Role) => {
const params = {
name: record.name,
status: record.status === 0 ? 1 : 0
};
try {
await updateRoleStatus(record.id, params)
proTableRef?.current?.submit(true);
} catch (error) {
}
} |
emm,那你还有问题吗 @freesaber |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
封装了一个组件proTable
使用proTable
我的问题是,proTableRef?.current?.submit();最后是执行的useAntdTable的submit。这个submit导致,分页重新回到第一页。怎样让分页数量固定到当前页呢。
The text was updated successfully, but these errors were encountered: