Browse Source

fix: handle pagination offset in gui

pull/8295/head
Pranav C 7 months ago
parent
commit
0cbc56464e
  1. 4
      packages/nc-gui/components/smartsheet/Pagination.vue
  2. 11
      packages/nc-gui/composables/useViewData.ts
  3. 9
      packages/nocodb/src/helpers/PagedResponse.ts

4
packages/nc-gui/components/smartsheet/Pagination.vue

@ -66,6 +66,8 @@ const isRTLLanguage = computed(() => isRtlLang(locale.value as keyof typeof Lang
const renderAltOrOptlKey = () => {
return isMac() ? '⌥' : 'ALT'
}
const tempPageVal = ref(page.value)
</script>
<template>
@ -118,7 +120,7 @@ const renderAltOrOptlKey = () => {
/>
<div v-else class="mx-auto flex items-center mt-n1" style="max-width: 250px">
<span class="text-xs" style="white-space: nowrap"> Change page:</span>
<a-input size="small" class="ml-1 !text-xs" type="number" @keydown.enter="changePage(page)">
<a-input v-model:value="tempPageVal" size="small" class="ml-1 !text-xs" type="number" @keydown.enter="changePage(tempPageVal)" @blur="tempPageVal = page">
<template #suffix>
<component :is="iconMap.returnKey" class="mt-1" @click="changePage(page)" />
</template>

11
packages/nc-gui/composables/useViewData.ts

@ -215,16 +215,17 @@ export function useViewData(
return message.error(await extractSdkResponseErrorMsg(error))
}
formattedData.value = formatData(response.list)
paginationData.value = response.pageInfo || {}
paginationData.value = response.pageInfo || paginationData.value || {}
isPaginationLoading.value = false
// to cater the case like when querying with a non-zero offset
// the result page may point to the target page where the actual returned data don't display on
const expectedPage = Math.max(1, Math.ceil(paginationData.value.totalRows! / paginationData.value.pageSize!))
if (expectedPage < paginationData.value.page!) {
await changePage(expectedPage)
if (paginationData.value.totalRows !== undefined && paginationData.value.totalRows !== null) {
const expectedPage = Math.max(1, Math.ceil(paginationData.value.totalRows! / paginationData.value.pageSize!))
if (expectedPage < paginationData.value.page!) {
await changePage(expectedPage)
}
}
if (viewMeta.value?.type === ViewTypes.GRID) {
loadAggCommentsCount()
}

9
packages/nocodb/src/helpers/PagedResponse.ts

@ -23,7 +23,7 @@ export class PagedResponseImpl<T> {
this.list = list;
if (count !== null) {
if (count !== null && count !== undefined) {
this.pageInfo = { totalRows: +count };
this.pageInfo.page = offset ? offset / limit + 1 : 1;
this.pageInfo.pageSize = limit;
@ -37,13 +37,14 @@ export class PagedResponseImpl<T> {
this.pageInfo.offset = offset;
delete this.pageInfo.page;
}
if (offset && offset >= +count) {
NcError.invalidOffsetValue(offset);
}
}
if (additionalProps) Object.assign(this, additionalProps);
if (offset && offset >= +count) {
NcError.invalidOffsetValue(offset);
}
}
list: Array<T>;

Loading…
Cancel
Save