ReferenceManyField 的 React-Admin 列表属性 IsRowExpandable

发布于 2025-01-12 05:57:49 字数 1332 浏览 0 评论 0原文

如果 ReferenceManyField 不存在任何条目,我喜欢将 IsRowExpandable 属性设置为 false。我如何访问 ReferenceManyField 计数或行?我发现了一个类似的问题,但我不知道如何在这种情况下访问这个总道具。 (获取 ReferenceManyField 计数?

https://marmelab.com/react-admin/List.html#isrowexpandable

  const ExpandCardWithDatagrid = () => {
    const classes = useStyles();
    return (
      <Card className={classes.subcard} variant="outlined">
        <CardContent>
          <ReferenceManyField reference="comments" target="postId">
            <Datagrid rowClick="edit">
              <NumberField source="myField1" />
              <NumberField source="myField2" />
               ...
            </Datagrid>
          </ReferenceManyField>
        </CardContent>
        <CardActions>
          <ViewFilteredContractTypesList />
        </CardActions>
      </Card>
    )
  }

  ...

    <List
      {...props}
      bulkActionButtons={false}/>}
    >
      <Datagrid
        rowClick="edit"
        isRowExpandable={??????????}    
        expand={<ExpandCardWithDatagrid />}>
...

I like to set the IsRowExpandable property to false, if no entries for the ReferenceManyField exists. How can i access the ReferenceManyField count or rows? I found a similar question, but i have no idea how can i access this total prop in this context. (Get ReferenceManyField Count?)

https://marmelab.com/react-admin/List.html#isrowexpandable

  const ExpandCardWithDatagrid = () => {
    const classes = useStyles();
    return (
      <Card className={classes.subcard} variant="outlined">
        <CardContent>
          <ReferenceManyField reference="comments" target="postId">
            <Datagrid rowClick="edit">
              <NumberField source="myField1" />
              <NumberField source="myField2" />
               ...
            </Datagrid>
          </ReferenceManyField>
        </CardContent>
        <CardActions>
          <ViewFilteredContractTypesList />
        </CardActions>
      </Card>
    )
  }

  ...

    <List
      {...props}
      bulkActionButtons={false}/>}
    >
      <Datagrid
        rowClick="edit"
        isRowExpandable={??????????}    
        expand={<ExpandCardWithDatagrid />}>
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

匿名。 2025-01-19 05:57:49

您可以通过创建自己的数据网格并访问其列表上下文来访问总数:

import { useListContext, List, Datagrid  } from 'react-admin';

const MyDatagrid = (props) => {
    const { total } = useListContext();

    return (
        <Datagrid {...props} isRowExpandable={row => total > 0}>
            <NumberField source="myField1" />
            <NumberField source="myField2" />
            //...
        </Datagrid>
    );
};

...

<List
    {...props}
    bulkActionButtons={false}
>
      <MyDatagrid
        rowClick="edit"
        expand={<ExpandCardWithDatagrid />}>
        ...

尽管如此,如果没有记录,我不知道这有什么用,但至少是一个关于如何访问列表的简单示例其子级中的上下文属性如 total

You could have access to the total by making your own Datagrid and accessing its list context:

import { useListContext, List, Datagrid  } from 'react-admin';

const MyDatagrid = (props) => {
    const { total } = useListContext();

    return (
        <Datagrid {...props} isRowExpandable={row => total > 0}>
            <NumberField source="myField1" />
            <NumberField source="myField2" />
            //...
        </Datagrid>
    );
};

...

<List
    {...props}
    bulkActionButtons={false}
>
      <MyDatagrid
        rowClick="edit"
        expand={<ExpandCardWithDatagrid />}>
        ...

Even though, if there are no records, I don't know how this is useful, but at least is a simple example on how to access a List context props like total within its children

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文