Posted as a bug since CodePen / examples do not handle re-selecting.
I believe DetailsList should handle re-sorting of the current selection. This applies to single and multi-select mode. If this isn't agreed as a fix then maybe an example of how to handle it would be handy. For discussion...
Sorting by column header click does not re-select previous items.
Either:
Are you willing to submit a PR to fix? (No)
Requested priority: (Normal)
@j-te thank you for reporting this issue. We are investigating.
Currently, it looks like default behavior is to maintain selection by index which is not desirable for obvious reasons in the Codepen above.
The answer up until now is likely that folks need to implement their own ISelection
interface which is non-trivial. Perhaps we can accommodate in current code or provide some guidance in documentation.
@j-te in scenarios where the items in the array supplied to DetailsList can change (for example due to sorting), the getKey prop must be supplied. Here's a codepen with a working example: https://codepen.io/krajeev/pen/RzNoLO I only made two small changes to our existing sample code: First, In _generateDocuments I am assigning a key to each document. The document's key does not change even when the items array is sorted. Second, I am also supplying getKey prop to DetailsList. We will be updating our sample code and documentation to reflect this.
Awesome debugging @Rajeev-K! Looking forward to the fix.
:tada:This issue was addressed in #9428, which has now been successfully released as [email protected]
.:tada:
Handy links:
Most helpful comment
@j-te in scenarios where the items in the array supplied to DetailsList can change (for example due to sorting), the getKey prop must be supplied. Here's a codepen with a working example: https://codepen.io/krajeev/pen/RzNoLO I only made two small changes to our existing sample code: First, In _generateDocuments I am assigning a key to each document. The document's key does not change even when the items array is sorted. Second, I am also supplying getKey prop to DetailsList. We will be updating our sample code and documentation to reflect this.