简体   繁体   中英

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. each program has relation to one organization. (saved in mongoDB anf I have a node server)

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.

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

I tried to create a custom function programsRowClick but I dont realy understand what should it return?

the react run on https://localhost:3000 the server run on https://localhost:4000/api

could you help me?

thank's!

Maybe this can help you: 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.

ie:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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