Skip to content
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

fix(table): pagination won't work if switch it to truthy value from undefined #2954

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/table/_example/pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export default {
* 此时,注意需要在 onPageChange 中对 pagination.current 和 pagination.pageSize 进行赋值
* */
pagination: {
// current: 2,
// pageSize: 5,
defaultCurrent: 2,
defaultPageSize: 5,
current: 2,
pageSize: 5,
// defaultCurrent: 2,
// defaultPageSize: 5,
total: TOTAL,
showJumper: true,
},
Expand All @@ -94,9 +94,11 @@ export default {
},
// 分页变化时触发该事件
onPageChange(pageInfo, newData) {
// 受控用法所需,即使用 pagination.current 和 pagination.pageSize 时,必须保留恢复下面 2 行代码
// this.pagination.current = pageInfo.current;
// this.pagination.pageSize = pageInfo.pageSize;
if (!this.pagination.defaultCurrent) {
// 受控用法所需,即使用 pagination.current 和 pagination.pageSize 时,必须保留恢复下面 2 行代码
this.pagination.current = pageInfo.current;
this.pagination.pageSize = pageInfo.pageSize;
}
console.log('page-change:', pageInfo, newData);
},
onSelectChange(selectedRowKeys, context) {
Expand Down
6 changes: 3 additions & 3 deletions src/table/hooks/usePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export default function usePagination(props: TdBaseTableProps, context: SetupCon
// 存在受控属性时,立即返回不再执行后续内容
if (isControlled) return;
updateDataSourceAndPaginate(
innerPagination.value.current ?? pagination.value.defaultCurrent,
innerPagination.value.pageSize ?? pagination.value.defaultPageSize,
innerPagination.value?.current ?? pagination.value.defaultCurrent,
innerPagination.value?.pageSize ?? pagination.value.defaultPageSize,
);
},
{ immediate: true },
Expand All @@ -65,7 +65,7 @@ export default function usePagination(props: TdBaseTableProps, context: SetupCon
props: pagination.value,
on: {
change: (pageInfo: PageInfo) => {
Object.assign(innerPagination.value, pageInfo);
innerPagination.value = pageInfo;
updateDataSourceAndPaginate(pageInfo.current, pageInfo.pageSize);
// Vue3 ignore this line
context.emit('page-change', pageInfo, dataSource.value);
Expand Down
Loading