diff --git a/packages/nc-gui/components/smartsheet/grid/GroupBy.vue b/packages/nc-gui/components/smartsheet/grid/GroupBy.vue index 4e70ba73bb..d314f47274 100644 --- a/packages/nc-gui/components/smartsheet/grid/GroupBy.vue +++ b/packages/nc-gui/components/smartsheet/grid/GroupBy.vue @@ -10,7 +10,13 @@ import type { Group } from '~/lib/types' const props = defineProps<{ group: Group - loadGroups: (params?: any, group?: Group) => Promise + loadGroups: ( + params?: any, + group?: Group, + options?: { + triggerChildOnly?: boolean + }, + ) => Promise loadGroupData: (group: Group, force?: boolean, params?: any) => Promise loadGroupPage: (group: Group, p: number) => Promise groupWrapperChangePage: (page: number, groupWrapper?: Group) => Promise @@ -42,6 +48,8 @@ const meta = inject(MetaInj, ref()) const fields = inject(FieldsInj, ref()) +const { gridViewPageSize } = useGlobal() + const scrollLeft = toRef(props, 'scrollLeft') const { isViewDataLoading, isPaginationLoading } = storeToRefs(useViewsStore()) @@ -133,9 +141,13 @@ const findAndLoadSubGroup = (key: any) => { const grp = vGroup.value.children.find((g) => `${g.key}` === k) if (grp) { if (grp.nested) { - if (!grp.children?.length) props.loadGroups({}, grp) + if (!grp.children[0].children?.length) { + props.loadGroups({}, grp, { + triggerChildOnly: true, + }) + } } else { - if (!grp.rows?.length || grp.count !== grp.rows?.length) _loadGroupData(grp) + if (!grp.rows?.length) _loadGroupData(grp) } } } @@ -146,7 +158,6 @@ const findAndLoadSubGroup = (key: any) => { const reloadViewDataHandler = (params: void | { shouldShowLoading?: boolean | undefined; offset?: number | undefined }) => { if (vGroup.value.nested) { props.loadGroups({ ...(params?.offset !== undefined ? { offset: params.offset } : {}) }, vGroup.value) - props.loadGroupAggregation(vGroup.value) } else { _loadGroupData(vGroup.value, true, { ...(params?.offset !== undefined ? { offset: params.offset } : {}), @@ -174,8 +185,13 @@ watch([() => vGroup.value.key], async (n, o) => { }) onMounted(async () => { - if (vGroup.value.root === true) { - await props.loadGroups({}, vGroup.value) + if (vGroup.value.root === true && !vGroup.value?.children?.length) { + await props.loadGroups( + { + limit: gridViewPageSize.value, + }, + vGroup.value, + ) } }) @@ -581,6 +597,7 @@ const bgColor = computed(() => { Promise + loadGroups: (params?: any, group?: Group, options?: { triggerChildOnly: boolean }) => Promise loadGroupData: (group: Group, force?: boolean, params?: any) => Promise loadGroupPage: (group: Group, p: number) => Promise groupWrapperChangePage: (page: number, groupWrapper?: Group) => Promise @@ -42,8 +42,6 @@ const isPublic = inject(IsPublicInj, ref(false)) const skipRowRemovalOnCancel = ref(false) -const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook()) - const { eventBus } = useSmartsheetStoreOrThrow() const route = router.currentRoute @@ -166,13 +164,6 @@ const reloadTableData = async (params: void | { shouldShowLoading?: boolean | un }) } -onBeforeUnmount(async () => { - // reset hooks - reloadViewDataHook?.off(reloadTableData) -}) - -reloadViewDataHook?.on(reloadTableData) - provide(IsGroupByInj, ref(true)) const pagination = computed(() => { @@ -273,14 +264,8 @@ async function deleteSelectedRowsWrapper() { await deleteSelectedRows() // reload table data - await reloadTableData({ shouldShowLoading: true }) + await reloadTableData({ shouldShowLoading: false }) } - -eventBus.on((event) => { - if (event === SmartsheetStoreEvents.GROUP_BY_RELOAD || event === SmartsheetStoreEvents.DATA_RELOAD) { - reloadViewDataHook?.trigger() - } -})