数据网格可展开在页面上的所有数据网格中打开。

huangapple go评论60阅读模式
英文:

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 Datagrids 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>

已修复的 Stackblitz

英文:

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 &lt;Datagrid&gt; in a &lt;ResourceContextProvider&gt; 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.

    &lt;ResourceContextProvider value=&quot;test&quot;&gt;
      &lt;Datagrid
        data={[{ id: 1 }, { id: 4 }]}
        rowClick=&quot;expand&quot;
        expand={&lt;&gt;Test&lt;/&gt;}
        header={&lt;&gt;Header&lt;/&gt;}
        prefix=&quot;test&quot;
      &gt;
        &lt;TextField label=&quot;ID&quot; source=&quot;id&quot; /&gt;
      &lt;/Datagrid&gt;
    &lt;/ResourceContextProvider&gt;

Fixed Stackblitz

huangapple
  • 本文由 发表于 2023年6月8日 17:34:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430473.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定