Search code examples
reactjsfieldadmin-on-restreact-admin

Modify what Text Field is displaying


I have my <ReferenceField> where I get some data to work with. In this case, I get attribute odata.type from my API. I want my <TextField> to display this attribute but I want to slightly modify the output that is displayed. Right now the attribute is displayed like this: HardwareDatabase.CPU. Basically I need to modify this output to be liek this: CPU.

Here is my code I described earlier:

  <ReferenceField label="Type" source="id" reference="Hardware">
    <TextField source="odata.type"/>
  </ReferenceField>

Any ideas how can I modify the output of the field?

Thank you in advance.


Solution

  • Try this:

    <ReferenceField label="Type" source="id" reference="Hardware">
       <FunctionField label="Name" render={record => record ? record["odata.type"].split(".")[1] : null} />
     </ReferenceField>