Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Admin: map resource data before showing in List

I want to perform additional operations on the returned elements from the API before showing them to the user. For example I have an enum field that is 0 or 1 and I would like to show some string instead of the raw value.

const List = (props: any) => (
  <List {...props}>
    <Datagrid rowClick="edit">
      <TextField source="name" />
      <TextField source="type" />
      <TextField source="value" />
    </Datagrid>
  </List>
);

The type column is a 0 or a 1 and I would like to show a string to the user. How can I map the data fetched by the <List> component before it gets passed to my <DataGrid>?

like image 750
Mark Uivari Avatar asked Jun 29 '26 14:06

Mark Uivari


1 Answers

if you have choices like this:

const TYPE_CHOICES = [
    {id: 0, name: 'One'},
    {id: 1, name: 'Two'},
];

use a SelectField to show the type:

  <SelectField source="type" choices={TYPE_CHOICES} />
like image 98
Ahmad Avatar answered Jul 01 '26 10:07

Ahmad