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 3cce2ddcb2..ee685d057f 100644 --- a/packages/table-core/src/features/ColumnSizing.ts +++ b/packages/table-core/src/features/ColumnSizing.ts @@ -208,10 +208,16 @@ 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 + /** + * 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()