Skip to content

Commit 358e129

Browse files
Lruihaohonghuangdc
authored andcommitted
feat(hooks): add scrollX computation for total table width in useNaiveTable
1 parent 9ea56c9 commit 358e129

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/hooks/common/table.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ export function useNaiveTable<ResponseData, ApiData>(options: UseNaiveTableOptio
3838
getColumns
3939
});
4040

41+
// calculate the total width of the table this is used for horizontal scrolling
42+
const scrollX = computed(() => {
43+
return result.columns.value.reduce((acc, column) => {
44+
return acc + Number(column.width ?? column.minWidth ?? 120);
45+
}, 0);
46+
});
47+
4148
scope.run(() => {
4249
watch(
4350
() => appStore.locale,
@@ -51,7 +58,10 @@ export function useNaiveTable<ResponseData, ApiData>(options: UseNaiveTableOptio
5158
scope.stop();
5259
});
5360

54-
return result;
61+
return {
62+
...result,
63+
scrollX
64+
};
5565
}
5666

5767
type PaginationParams = Pick<PaginationProps, 'page' | 'pageSize'>;

0 commit comments

Comments
 (0)