question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Show / SimpleShowLayout Does not Render Fields When in a Grid

See original GitHub issue

What you were expecting: When using material UI Grid in an Edit or Create page, the field contents displayed perfect. I expected the Grid to work the same way on a Show page.

What happened instead: When using the same Grid on a Show page, the fields did not display.

Steps to reproduce: Modify the demo/example https://marmelab.com/react-admin/Show.html#the-simpleshowlayout-component to include a Material UI Grid that wraps the fields.

Related code:

import Grid from '@material-ui/core/Grid';

export const PostShowx = (props) => (
    <Show {...props}>
        <SimpleShowLayout>
			<Grid container >
				<Grid item xs={6}>
					<TextField source="title" />
				</Grid>
				<Grid item xs={6}>
					<TextField source="name" />
				</Grid>
			</Grid>
            <RichTextField source="body" />
        </SimpleShowLayout>
    </Show>
);

Even a simple html table seems to not render the TextFields:

export const PostShow = (props) => (
    <Show {...props}>
        <SimpleShowLayout>
			<table>
				<tr>
					<td>
						<TextField source="title" />
					</td>
					<td>			
					       <TextField source="name" />
					</td>
				</tr>
			</table>
            <RichTextField source="body" />
        </SimpleShowLayout>
    </Show>
);

Note: It works just fine on an Edit page:

export const PostEdit = (props) => (
    <Edit title={<PostTitle />} {...props}>
        <SimpleForm>
            <DisabledInput source="id" />
			<Grid container >
				<Grid item xs={6}>
					<ReferenceInput label="User" source="userId" reference="users">
						<SelectInput optionText="name" />
					</ReferenceInput>
				</Grid>
				<Grid item xs={6}>
					<TextInput source="title" />
				</Grid>
			</Grid>
            <LongTextInput source="body" />
        </SimpleForm>
    </Edit>
);

Environment

  • React-admin version: 2.2.0
  • React version: 16.4.1
  • Browser: Tried on both Firefox and Chrome

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
heyimbruceleecommented, Feb 1, 2019

Faced the same issue trying to use Grid. Simple workaround : use className 🎉

example : <DateField source="profile.birthdate" className="ra-field-50 " /> <TextField source="profile.firstname" className="ra-field-clear ra-field-50" /> <TextField source="profile.lastname" className="ra-field-50" />

.ra-field.ra-field-50{
    width: 50%;
    padding-right: 10px;
    float: left;
  }
.ra-field.ra-field-clear{
    clear:both;
  }

for input fields use formClassName <TextInput source="profile.lastname" formClassName="ra-field-50" />

implement it how you like, add media queries and so on…

6reactions
djhicommented, Nov 9, 2018

Hence the Simple in its name and why we also provide the TabbedShowLayout and TabbedForm components. For other cases, you’ll have to implement your own layout/form

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to organise a Show layout in React Admin using a ...
ShowLayout components from rendering the Field components inside them properly. I was hoping to be able to do something like this: <Show {......
Read more >
The Show Component - React-admin - Marmelab
<Show> doesn't render any field by default - it delegates this to its children. Show layout components grab the record from the RecordContext...
Read more >
React Data Grid: Rendering - AG Grid
When using AG Grid React, all of the grid's core rendering (headers, rows, cells etc) is rendered using React. AG Grid React shares...
Read more >
Data Grid - Column definition - MUI X
Sometimes a column might not have a corresponding value, or you might want to render a combination of different fields. To achieve that,...
Read more >
GridProps - React Data Grid Component - KendoReact API
If virtualization is enabled, the columns outside the view are not rendered. data? "null" | any[] | DataResult. Sets the data of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found