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
If you look at the call implementation here, you can find two issues:
cellA is not of type DataTableCell but is directly the value of the cell, same for cellB.
sortRowOptions is missing the key and compare properties, hence making it impossible to know in which column we are and choose the correct sorting strategy
As a work around we can of course force a cast such as:
sortRow={customSort as DataTableProps<Item, string[]>['sortRow']}
Then define the customSort with the real implementation signature:
Open the developer tool of the browser, and switch to the console
Click on the Status header on the table to sort
Issue 1: You can see what cellA.value is undefined, and cellA is actually the value
Issue 2: try adding the key or compare property to the deconstructed 3rd argument { sortDirection, sortStates, locale }, and you will see the type script error:
Suggested Severity
Severity 3 = User can complete task, and/or has a workaround within the user experience of a given component.
Submitted PR 18073 to fix that, feel free to use it or not. It's the first time I'm contributing and I tried to follow all guidelines, but I might have missed something.
Package
@carbon/react
Browser
Chrome
Package version
1.70.0
React version
18.3.1
Description
The TypeScript definition of sortRow for Datatable is wrong:
If you look at the call implementation here, you can find two issues:
cellA
is not of type DataTableCell but is directly the value of the cell, same forcellB
.sortRowOptions
is missing thekey
andcompare
properties, hence making it impossible to know in which column we are and choose the correct sorting strategyAs a work around we can of course force a cast such as:
Then define the customSort with the real implementation signature:
I created another sandbox with the workaround.
But that would be nice it the type was correct.
Reproduction/example
https://stackblitz.com/edit/github-lctgtu-4rv1zf?file=src%2FApp.tsx
Steps to reproduce
cellA.value
is undefined, andcellA
is actually the valuekey
orcompare
property to the deconstructed 3rd argument{ sortDirection, sortStates, locale }
, and you will see the type script error:Suggested Severity
Severity 3 = User can complete task, and/or has a workaround within the user experience of a given component.
Application/PAL
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: