Resolve IDs before createTable #5811
Unanswered
torztomasz
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, Tanstack Table resolves column IDs inside the
createTable
function, which is called when passing column definitions (columnDefs
) to theuseReactTable
hook. This process works as follows:columnHelper
.columnDefs
are passed touseReactTable
.useReactTable
, thecreateTable
function resolves the column ID using the following logic:table.getAllColumns().at(0).id
, after the table is created.The Problem
This approach delays ID resolution until the table is created, preventing developers from accessing resolved IDs beforehand. This limitation impacts use cases such as syncing sorting states across multiple tables where column IDs need to match, as there is no way to check if one table's column can be sorted by another table's
columnId
.Proposed Solutions
To address this, I propose two potential solutions:
Solution 1: Resolve IDs in Column Helper Functions
Move ID resolution logic into the column helper functions (
columnHelper
). This would enable resolved IDs to be available as soon as the column definitions are created, even before they are passed touseReactTable
.Flow:
columnDefs
usingcolumnHelper
.columns[0].id
.Solution 2: Expose an ID Resolution Utility
Extract the ID resolution logic into a standalone utility function, making it reusable and accessible to users. For example:
This function could then be exposed by Tanstack Table, allowing developers to manually resolve IDs when needed.
Flow:
columnDefs
usingcolumnHelper
.Conclusion
Both solutions aim to provide earlier and more consistent access to resolved IDs.
Looking forward to hearing thoughts from the community! Which solution do you prefer, or do you see any alternative approaches?
Beta Was this translation helpful? Give feedback.
All reactions