Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add header.getAfter API #5890

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api/features/column-sizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion packages/table-core/src/features/ColumnSizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

//
Expand Down Expand Up @@ -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()
Expand Down