Skip to content

Conversation

mikhail-fedosenko
Copy link

@mikhail-fedosenko mikhail-fedosenko commented Sep 19, 2025

Problem

It's not possible to create distinct List views that use separate and independent record selection states.

Solution

Add selectionStoreKey to List, useListController and, eventually, to useRecordSelection. If passed, it's used inside useRecordSelection as store key.

@mikhail-fedosenko
Copy link
Author

I'm stuck with the requirement on my work project to have independent list views that need to have independent selection states.
Would be nice if we could have some kind of custom storeKey for a useRecordSelection.

@fzaninotto
Copy link
Member

Thanks for your PR. But, as explained in #7401 (comment):

If row selection isn't tied to a resource, then when a user deletes a record, it may remain selected without any ability to unselect it.

We've chosen to store one selection per resource for that reason. We won't support the use case you describe.

If your need doesn't match this design, then don't use our List component, and build your own based on react-admin hooks.

I'll be waiting for further feedback before closing this RFC.

@mikhail-fedosenko
Copy link
Author

Well, the list is tied to a resouce. I just want to "namespace" the selections. My user case: we have members. A member can belong to a team. When viewing the list of members of a team i'd like to keep selection separate between teams.

Also, i don't understand this statement:

then when a user deletes a record, it may remain selected without any ability to unselect it.

On the UI i can clearly see the cross icon button that clears the selection even if the list or the current page of the list doesn't represent the selected record:
image

I suppose, if the list has no records, it will show "empty list component" which, presumably, has no "selection state" green bar. So, again, should not be a problem.

@fzaninotto
Copy link
Member

When a user deletes a record, react-admin removes this record from the selection. This is done here:

Your screenshot shows the problem if you use another selection state: the bulk actions toolbar shows that 1 record is selected, but no record appears selected in the DataTable. This is incoherent.

The only solution I can see is to modify both the useListController to allow namespaced selections and useDeleteController to remove the deleted record from all namespaced selections. If you feel like implementing this, please go ahead.

@mikhail-fedosenko
Copy link
Author

Yes, sure, the connection to selectedIds is spread across the codebase (this is what that contradicts the idea of modularity and replacebility of modules in React-Admin...), so I'll have to invent smth that will allow to clear selected ids in different places.
I see it's like an app state (store somewhere, in this case - in localstorage) that used in several places... (while the key is basically hardcoded in those places).

Also, the screenshot i've posted is completely legitimate in React-Admin without any modifications - just select an item, then go to different page or apply other filters...

And talking about record deletion and selected state I've realized that I have a bug in my project: we have several React-Admin resources that actually map to single resource in our system, thet are just different perspectives of it (e.g. a member, and a member of a team - they are the same entity, but use different endpoints, thus, different resources in React-Admin). So, whenever I delete a member in one place, the selection may not be cleared in another place...
This has never happened though.

Ok, I'll take a look and will try to think over potential implementation that will cover both useListController/List/useRecordSelection and delete flow.
You can close the PR for now.

@fzaninotto fzaninotto closed this Sep 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants