简体   繁体   English

如何在 react-admin 数据网格中为 rowClick 定义自定义 function?

[英]How to define a custom function to rowClick in react-admin datagrid?

I'm building an app with react-admin, I have an organizations resource and programs resource.我正在使用 react-admin 构建一个应用程序,我有一个组织资源和程序资源。 each program has relation to one organization.每个程序都与一个组织有关。 (saved in mongoDB anf I have a node server) (保存在 mongoDB 中我有一个节点服务器)

I created a custom list to organizations resource.我为组织资源创建了一个自定义列表。

 <List {...props}>
    <Datagrid rowClick={programsRowClick}>
        <TextField source="name" />
        <EditButton  />
    </Datagrid>
</List>

I want when we click on organization row to recieve all the programs that have the same organizationId.我希望当我们单击组织行以接收具有相同组织 ID 的所有程序时。

the API is: https://localhost:4000/api/organization/${id}/programs API 是:https://localhost:4000/api/organization/${id}/programs

I tried to create a custom function programsRowClick but I dont realy understand what should it return?我试图创建一个自定义 function程序RowClick,但我真的不明白它应该返回什么?

the react run on https://localhost:3000 the server run on https://localhost:4000/api反应在 https://localhost:3000 上运行 服务器在 https://localhost:4000/api 上运行

could you help me?你可以帮帮我吗?

thank's!谢谢!

Maybe this can help you: https://marmelab.com/react-admin/List.html#expand也许这可以帮助你: https://marmelab.com/react-admin/List.html#expand

It allows you to display a custom component in the list on row click.它允许您在单击行时在列表中显示自定义组件。

Otherwise rowClick accept a function which returns a path.否则rowClick接受返回路径的 function。

ie: IE:

<RA.Datagrid rowClick={(id: RA.Identifier) => `/${resource}/${id}/${customRoute}`}>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM