Replies: 1 comment
-
Thanks for the suggestion and extensive documentation! I think this would be great addition to the docs for Are you open to submitting a PR to update the docs? I can help you through the process. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I believe we could possibly provide more detailed documentation around:
setKey
propI struggled to understand why the selection on
DetailsList
doesn't work. The problem was: I didn't assign thesetKey
prop:The only documentation available for
setKey
is:https://docs.microsoft.com/en-us/javascript/api/react/idetailslistprops?view=office-ui-fabric-react-latest#@fluentui-react-idetailslistprops-setkey-member
The same is true for Intellisense in the editor:
Even with this explanation, I was struggling to understand why I have to assign any string to it.
Since we have the
getKey
method,setKey
seemed like a setter for the thing for which thegetKey
is getter.However, these two are not related. Rather,
setKey
means "the key of the set", where the set is currently loaded data toDetailsList
.Whenever the
setKey
is changed, grid selection is cleared. So you would probably want to update thesetKey
with each grid reload (if you don't want to keep the previous selection). Probably using a counter (of reloads), or generated GUID (upon each reload).I missed the word "items" (so it's not a single item, but many items at once - "a set"):
A key that uniquely identifies the given **items**.
Furthermore, if one doesn't assign the
getKey
callback, then the default key will be "key". This variable name could sometimes exist in the retrieved data (API response), so we must use another key. And that's what thegetKey
is for.If one wants to use some variable name that won't clash (for instance
__id__
), then they have to assign it to every data row:Then, the corresponding
getKey
method should be:This method should then be used both by
Selection
object, and byDetailsList
(for using it as a key in React).Selection (custom hook):
DetailsList:
Beta Was this translation helpful? Give feedback.
All reactions