英文:
Datagrid expandable opens on all Datagrids on page
问题
当在同一页上有多个 Datagrid
组件时,可展开功能会混淆,并在页面上所有 Datagrid
上打开具有相同 id
的记录。请查看此处标签列表的示例:https://stackblitz.com/edit/github-s7cbum?file=src%2Ftags%2FTagList.tsx
打开具有 id = 1
的条目会在两个 Datagrid
上同时打开记录,但对于 id = 2 或 3
,它会按预期工作。
英文:
When having multiple Datagrid
components on one page the expandable function gets confused and opens the record with the same id
on all Datagrids
on the page. See example on the tag list here: https://stackblitz.com/edit/github-s7cbum?file=src%2Ftags%2FTagList.tsx
Opening up the entry with id = 1
opens up the record on both Datagrid
s but for id = 2 or 3
it works as intended.
答案1
得分: 2
我怕这是框架的当前限制。
确实,扩展的键存储在存储中,使用此键:${resource}.datagrid.expanded
,即状态在给定资源之间共享。(来源)
我能想到的唯一解决方法是一个不太好的办法:你可以将第二个 <Datagrid>
包装在一个 <ResourceContextProvider>
中,以强制使用另一个资源。你可能需要结合一个围绕 dataProvider
的代理,将针对这个虚拟资源的 API 调用映射到正确的资源。
<ResourceContextProvider value="test">
<Datagrid
data={[{ id: 1 }, { id: 4 }]}
rowClick="expand"
expand={<><>Test<></>}
header={<><>Header<></>}
prefix="test"
>
<TextField label="ID" source="id" />
</Datagrid>
</ResourceContextProvider>
英文:
I'm afraid that's a current limitation of the framework.
Indeed the expanded keys are stored in the Store using this key: ${resource}.datagrid.expanded
, i.e. the state is shared for a given resource. (source)
The only workaround I can think of is a dirty one: you can wrap your second <Datagrid>
in a <ResourceContextProvider>
to force using another resource. You might want to couple that with a Proxy around the dataProvider
to map the API calls targeting this dummy resource to the correct one.
<ResourceContextProvider value="test">
<Datagrid
data={[{ id: 1 }, { id: 4 }]}
rowClick="expand"
expand={<>Test</>}
header={<>Header</>}
prefix="test"
>
<TextField label="ID" source="id" />
</Datagrid>
</ResourceContextProvider>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论