You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: new column pinning, sizing, ordering APIs for easier sticky pinning (#5344)
* improved memo method to accept depArgs
getMemoOptions method to reduce memo boilerplate
new ColumnSizing getAfter API (similar to getStart)
added memoization to column.getStart method
new Ordering column.getIndex API
new Ordering column.getIsFirstColumn API
new Ordering column.getIsLastColumn API
improved table._getPinnedRows memo performance
* update column pinning example and docs
* update lock file
* even better column sizing performance
* smaller code
Returns the index of the column in the order of the visible columns. Optionally pass a `position` parameter to get the index of the column in a sub-section of the table.
Returns `true` if the column is the first column in the order of the visible columns. Optionally pass a `position` parameter to check if the column is the first in a sub-section of the table.
Returns `true` if the column is the last column in the order of the visible columns. Optionally pass a `position` parameter to check if the column is the last in a sub-section of the table.
Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the column.
78
+
Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the column, measuring the size of all preceding columns.
79
+
80
+
Useful for sticky or absolute positioning of columns. (e.g. `left` or `transform`)
Returns the offset measurement along the row-axis (usually the x-axis for standard tables) for the column, measuring the size of all succeeding columns.
89
+
90
+
Useful for sticky or absolute positioning of columns. (e.g. `right` or `transform`)
81
91
82
92
### `getCanResize`
83
93
@@ -134,7 +144,7 @@ Returns an event handler function that can be used to resize the header. It can
134
144
135
145
The dragging and release events are automatically handled for you.
TanStack Table offers state and APIs helpful for implementing column pinning features in your table UI. You can implement column pinning in multiple ways. You can either split pinned columns into their own separate tables, or you can keep all columns in the same table, but use the pinning state to order the columns correctly and use sticky CSS to pin the columns to the left or right.
25
+
26
+
### How Column Pinning Affects Column Order
27
+
18
28
There are 3 table features that can reorder columns, which happen in the following order:
19
29
20
30
1.**Column Pinning** - If pinning, columns are split into left, center (unpinned), and right pinned columns.
21
31
2. Manual [Column Ordering](../guide/column-ordering) - A manually specified column order is applied.
22
32
3.[Grouping](../guide/grouping) - If grouping is enabled, a grouping state is active, and `tableOptions.columnGroupingMode` is set to `'reorder' | 'remove'`, then the grouped columns are reordered to the start of the column flow.
33
+
34
+
The only way to change the order of the pinned columns is in the `columnPinning.left` and `columnPinning.right` state itself. `columnOrder` state will only affect the order of the unpinned ("center") columns.
35
+
36
+
### Column Pinning State
37
+
38
+
Managing the `columnPinning` state is optional, and usually not necessary unless you are adding persistent state features. TanStack Table will already keep track of the column pinning state for you. Manage the `columnPinning` state just like any other table state if you need to.
A very common use case is to pin some columns by default. You can do this by either initializing the `columnPinning` state with the pinned columnIds, or by using the `initialState` table option
60
+
61
+
```jsx
62
+
consttable=useReactTable({
63
+
//...
64
+
initialState: {
65
+
columnPinning: {
66
+
left: ['expand-column'],
67
+
right: ['actions-column'],
68
+
},
69
+
//...
70
+
}
71
+
//...
72
+
});
73
+
```
74
+
75
+
### Useful Column Pinning APIs
76
+
77
+
> Note: Some of these APIs are new in v8.12.0
78
+
79
+
There are a handful of useful Column API methods to help you implement column pinning features:
80
+
81
+
-[`column.getCanPin`](../api/features/pinning#getcanpin): Use to determine if a column can be pinned.
82
+
-[`column.pin`](../api/features/pinning#pin): Use to pin a column to the left or right. Or use to unpin a column.
83
+
-[`column.getIsPinned`](../api/features/pinning#getispinned): Use to determine where a column is pinned.
84
+
-[`column.getStart`](../api/features/pinning#getstart): Use to provide the correct `left` CSS value for a pinned column.
85
+
-[`column.getAfter`](../api/features/pinning#getafter): Use to provide the correct `right` CSS value for a pinned column.
86
+
-[`column.getIsLastColumn`](../api/features/pinning#getislastcolumn): Use to determine if a column is the last column in its pinned group. Useful for adding a box-shadow
87
+
-[`column.getIsFirstColumn`](../api/features/pinning#getisfirstcolumn): Use to determine if a column is the first column in its pinned group. Useful for adding a box-shadow
88
+
89
+
### Split Table Column Pinning
90
+
91
+
If you are just using sticky CSS to pin columns, you can for the most part, just render the table as you normally would with the `table.getHeaderGroups` and `row.getVisibleCells` methods.
92
+
93
+
However, if you are splitting up pinned columns into their own separate tables, you can make use of the `table.getLeftHeaderGroups`, `table.getCenterHeaderGroups`, `table.getRightHeaderGroups`, `row.getLeftVisibleCells`, `row.getCenterVisibleCells`, and `row.getRightVisibleCells` methods to only render the columns that are relevant to the current table.
* 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.
168
+
* 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 (left) headers in relation to the current column.
* 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 (right) headers in relation to the current column.
* Returns the index of the column in the order of the visible columns. Optionally pass a `position` parameter to get the index of the column in a sub-section of the table
* Returns `true` if the column is the first column in the order of the visible columns. Optionally pass a `position` parameter to check if the column is the first in a sub-section of the table.
* Returns `true` if the column is the last column in the order of the visible columns. Optionally pass a `position` parameter to check if the column is the last in a sub-section of the table.
0 commit comments