fix(data-table): pagination error

This commit is contained in:
07akioni 2021-07-29 09:09:41 +08:00
parent ea5ae8725d
commit ce8ff038cd
3 changed files with 25 additions and 6 deletions

View File

@ -1,5 +1,11 @@
# CHANGELOG # CHANGELOG
## 2.15.11 (2021-07-29)
### Fixes
- Fix `n-data-table` pagination's error.
## 2.15.10 (2021-07-29) ## 2.15.10 (2021-07-29)
### Feats ### Feats

View File

@ -1,5 +1,11 @@
# CHANGELOG # CHANGELOG
## 2.15.11 (2021-07-29)
### Fixes
- 修复 `n-data-table` pagination 的报错
## 2.15.10 (2021-07-29) ## 2.15.10 (2021-07-29)
### Feats ### Feats

View File

@ -123,10 +123,7 @@ export function useTableData (
const { pageCount } = pagination const { pageCount } = pagination
if (pageCount !== undefined) return pageCount if (pageCount !== undefined) return pageCount
} }
const { value: filteredData } = filteredDataRef return undefined
if (filteredData.length === 0) return 1
const { value: pageSize } = mergedPageSizeRef
return Math.ceil(filteredData.length / pageSize)
}) })
const mergedSortStateRef = computed<SortState | null>(() => { const mergedSortStateRef = computed<SortState | null>(() => {
@ -319,7 +316,14 @@ export function useTableData (
} }
} }
const mergedItemCountRef = computed(() => { const mergedItemCountRef = computed(() => {
if (props.remote) return (props.pagination as PaginationProps).itemCount if (props.remote) {
const { pagination } = props
if (pagination) {
const { itemCount } = pagination
if (itemCount !== undefined) return itemCount
}
return undefined
}
return filteredDataRef.value.length return filteredDataRef.value.length
}) })
const mergedPaginationRef = computed<PaginationProps>(() => { const mergedPaginationRef = computed<PaginationProps>(() => {
@ -335,7 +339,10 @@ export function useTableData (
// key still exists but value is undefined // key still exists but value is undefined
page: mergedCurrentPageRef.value, page: mergedCurrentPageRef.value,
pageSize: mergedPageSizeRef.value, pageSize: mergedPageSizeRef.value,
pageCount: mergedPageCountRef.value, pageCount:
mergedItemCountRef.value === undefined
? mergedPageCountRef.value
: undefined,
itemCount: mergedItemCountRef.value itemCount: mergedItemCountRef.value
} }
}) })