From 2a8102b3ee7156eeb6f672301fa14ca6cbfff06d Mon Sep 17 00:00:00 2001 From: Joshua J <31038284+joshuajaco@users.noreply.github.com> Date: Tue, 28 Jan 2025 13:35:31 +0100 Subject: [PATCH 1/2] docs: Fix `header.getStart` API docs link --- packages/table-core/src/features/ColumnSizing.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/table-core/src/features/ColumnSizing.ts b/packages/table-core/src/features/ColumnSizing.ts index 3cce2ddcb2..2105e7a6b2 100644 --- a/packages/table-core/src/features/ColumnSizing.ts +++ b/packages/table-core/src/features/ColumnSizing.ts @@ -208,7 +208,7 @@ export interface ColumnSizingHeader { getSize: () => number /** * Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all preceding headers. - * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#getstart) + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#getstart-1) * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) */ getStart: (position?: ColumnPinningPosition) => number From 0983345c366ff087a224521cef296312d6b55db7 Mon Sep 17 00:00:00 2001 From: Joshua J <31038284+joshuajaco@users.noreply.github.com> Date: Tue, 28 Jan 2025 13:36:30 +0100 Subject: [PATCH 2/2] feat(table-core): add `header.getAfter` API --- docs/api/features/column-sizing.md | 8 ++++++++ packages/table-core/src/features/ColumnSizing.ts | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/docs/api/features/column-sizing.md b/docs/api/features/column-sizing.md index 0bf7631be8..0b5aac7213 100644 --- a/docs/api/features/column-sizing.md +++ b/docs/api/features/column-sizing.md @@ -131,6 +131,14 @@ getStart: (position?: ColumnPinningPosition) => number Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all preceding headers. +### `getAfter` + +```tsx +getAfter: (position?: ColumnPinningPosition) => number +``` + +Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all succeeding headers. + ### `getResizeHandler` ```tsx diff --git a/packages/table-core/src/features/ColumnSizing.ts b/packages/table-core/src/features/ColumnSizing.ts index 2105e7a6b2..ee685d057f 100644 --- a/packages/table-core/src/features/ColumnSizing.ts +++ b/packages/table-core/src/features/ColumnSizing.ts @@ -212,6 +212,12 @@ export interface ColumnSizingHeader { * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) */ getStart: (position?: ColumnPinningPosition) => number + /** + * Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the header. This is effectively a sum of the offset measurements of all preceding headers. + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#getafter-1) + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) + */ + getAfter: (position?: ColumnPinningPosition) => number } // @@ -339,6 +345,15 @@ export const ColumnSizing: TableFeature = { return 0 } + header.getAfter = () => { + const rightIndex = header.headerGroup.headers.length - header.index - 1 + if (rightIndex > 0) { + const nextSiblingHeader = header.headerGroup.headers[header.index + 1]! + return nextSiblingHeader.getAfter() + nextSiblingHeader.getSize() + } + + return 0 + } header.getResizeHandler = _contextDocument => { const column = table.getColumn(header.column.id) const canResize = column?.getCanResize()