-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Use accessorFn
instead of cell
to render status
#55196
Conversation
Size Change: -2 B (0%) Total Size: 1.65 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, though it's harmless as is now, because we can have access through props.row.original.status
.
Thanks for the brain dump! Trying to wrap my head around this tanstack thing, so this is helpful. |
cell: ( props ) => | ||
postStatuses[ props.row.original.status ] ?? | ||
props.row.original.status, | ||
accessorFn: ( page ) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, apparently, when a field has an accessorFn
the column is automatically made sortable, unless set otherwise. Fix at #55210
Related #55083
Follow-up to #54966
What?
The fields (ColumnsDef in tanstack) provide two functions to render data for each cell: accessorFn and cell. We were using
cell
to provide the data for thestatus
but we should useaccessorFn
instead.Why?
The
accessorFn
is the callback that provides the value for this cell. On the other hand,cell
is for rendering the data in the UI should you want to render anything different from the value (e.g.: wrap the value into a link, add a text transformation, etc.).For example, let's say a cell wanted to access the value of
status
for its row. This is how you do it:However, because the
status
row does not provide anyaccessorFn
,props.row.getValue( 'status' )
returns undefined. This PR fixes it and makes it return the proper value.Testing Instructions
Tests that it works as before visually for users:
Make sure the value is returned for the cell: