I've created a number of Show views in a new React-Admin project. Rather than have the fields just form a single column I would like to use Material UI's Grid component to arrange them into a more efficient and helpful layout. Unfortunately this stops React Admin's ...ShowLayout components from rendering the Field components inside them properly.
I was hoping to be able to do something like this:
<Show {...props}>
<SimpleShowLayout>
<Grid container>
<Grid item>
<TextField source="firstName" />
</Grid>
<Grid item>
<TextField source="lastName" />
</Grid>
</Grid>
</SimpleShowLayout>
</Show>
I've also had a go at creating wrapper components to try to ensure the right props get passed along to the Field components, to no avail. How can I better arrange the fields in a layout? Do I have to fall back to "manually" styling the contents of a show layout using custom styles? If so that seems a shame given that RA uses MUI so heavily for rendering and it already provides a framework for doing this.
Material design's responsive UI is based on a 12-column grid layout. This grid creates visual consistency between layouts, while allowing flexibility across a wide variety of designs.
Material Design's grid systemA grid system defines a set of measurements to place elements or components on the page based on successive columns and rows. The grid system in Material Design is visually balanced. It adapts to screen sizes and orientation, which ensures a consistent layout across pages.
The responsive UI in Material-UI is based on a 12-column grid layout. To understand this better, imagine the website you are looking at is split into 12 even columns. The number you pass will set the Grid to take up that many columns in the breakpoint width.
In case somebody is still stumbling upon this issue - just passing the props forward is not enough based on how the SimpleShowLayout works behind the scenes.
I am working on a react-admin
npm package where I have implemented a basic recursive GridShowLayout
. It allows you to nest as many <Grid>
components as needed like @Pedro Viera have shown and the react-admin fields
will still recieve the needed props
accordinly.
There is also a BoxedShowLayout
, you can check it out here: ra-compact-ui/GridShowLayout
Example:
<Show {...props}>
<GridShowLayout>
<Grid container>
<Grid >
<TextField source="firstName" />
</Grid >
<Grid >
<TextField source="lastName" />
</Grid >
</Grid >
</GridShowLayout>
</Show>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With