You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`children`| Required | Element | n/a | The list of `<Field>` components to render as columns. |
44
+
|`body`| Optional | Element |`<Datagrid Body>`| The component used to render the body of the table. |
45
+
|`bulkActionButtons`| Optional | Element |`<BulkDelete Button>`| The component used to render the bulk action buttons. |
46
+
|`empty`| Optional | Element |`<Empty>`| The component used to render the empty table. |
47
+
|`expand`| Optional | Element || The component used to render the expand panel for each row. |
48
+
|`expandSingle`| Optional | Boolean |`false`| Whether to allow only one expanded row at a time. |
49
+
|`header`| Optional | Element |`<Datagrid Header>`| The component used to render the table header. |
50
+
|`hover`| Optional | Boolean |`true`| Whether to highlight the row under the mouse. |
51
+
|`isRowExpandable`| Optional | Function |`() => true`| A function that returns whether a row is expandable. |
52
+
|`isRowSelectable`| Optional | Function |`() => true`| A function that returns whether a row is selectable. |
53
+
|`optimized`| Optional | Boolean |`false`| Whether to optimize the rendering of the table. |
54
+
|`rowClick`| Optional | mixed || The action to trigger when the user clicks on a row. |
55
+
|`rowStyle`| Optional | Function || A function that returns the style to apply to a row. |
56
+
|`rowSx`| Optional | Function || A function that returns the sx prop to apply to a row. |
57
+
|`size`| Optional |`'small'` or `'medium'`|`'small'`| The size of the table. |
58
+
|`sx`| Optional | Object || The sx prop passed down to the Material UI `<Table>` element. |
59
59
60
60
Additional props are passed down to [the Material UI `<Table>` element](https://mui.com/material-ui/api/table/).
61
61
@@ -107,39 +107,6 @@ const PostList = () => (
107
107
exportdefaultPostList;
108
108
```
109
109
110
-
## `children`
111
-
112
-
`<Datagrid>` accepts a list of Field components as children. It inspects each child's `source` and/or `label` props to determine the name of the column.
113
-
114
-
What's a Field component? Simply a component that reads the record (via `useRecordContext`) and renders a value. React-admin includes many Field components that you can use as children of `<Datagrid>` (`<TextField>`, `<NumberField>`, `<DateField>`, `<ReferenceField>`, and many more). Check [the Fields documentation](./Fields.md) for more information.
`<Datagrid>` also inspects its children for `headerClassName` and `cellClassName` props, and gives the class names to the headers and the cells of that column.
140
-
141
-
Finally, `<Datagrid>` inspects children for props that indicate how it should be sorted (see [the Customizing The Sort Order For Columns section](#customizing-column-sort)) below.
`<Datagrid>` accepts a list of Field components as children. It inspects each child's `source` and/or `label` props to determine the name of the column.
350
+
351
+
What's a Field component? Simply a component that reads the record (via `useRecordContext`) and renders a value. React-admin includes many Field components that you can use as children of `<Datagrid>` (`<TextField>`, `<NumberField>`, `<DateField>`, `<ReferenceField>`, and many more). Check [the Fields documentation](./Fields.md) for more information.
`<Datagrid>` also inspects its children for `headerClassName` and `cellClassName` props, and gives the class names to the headers and the cells of that column.
377
+
378
+
Finally, `<Datagrid>` inspects children for props that indicate how it should be sorted (see [the Customizing The Sort Order For Columns section](#customizing-column-sort)) below.
379
+
380
380
## `empty`
381
381
382
382
It's possible that a Datagrid will have no records to display. If the Datagrid's parent component does not handle the empty state, the Datagrid will display a message indicating there are no results. This message is translatable and its key is `ra.navigation.no_results`.
## `optimized`: Better Performance For Large Tables
609
+
## `optimized`
610
610
611
611
When displaying large pages of data, you might experience some performance issues.
612
612
This is mostly due to the fact that we iterate over the `<Datagrid>` children and clone them.
@@ -628,90 +628,92 @@ const PostList = () => (
628
628
);
629
629
```
630
630
631
-
## `rowStyle`
632
-
633
-
You can customize the `<Datagrid>` row style (applied to the `<tr>` element) based on the record, thanks to the `rowStyle` prop, which expects a function. React-admin calls this function for each row, passing the current record and index as arguments. The function should return a style object, which react-admin uses as a `<tr style>` prop.
631
+
## `rowClick`
634
632
635
-
For instance, this allows to apply a custom background to the entire row if one value of the record - like its number of views - passes a certain threshold.
633
+
You can catch clicks on rows to redirect to the show or edit view by setting the `rowClick` prop:
You can customize the styles of rows and cells in `<Datagrid>` (applied to the `<DatagridRow>` element) based on the record, thanks to the `rowSx` prop, which expects a function. React-admin calls this function for each row, passing the current record and index as arguments. The function should return a Material UI [`sx`](https://mui.com/system/getting-started/the-sx-prop/), which react-admin uses as a `<TableRow sx>` prop.
649
+
* "edit" to redirect to the edition view
650
+
* "show" to redirect to the show view
651
+
* "expand" to open the `expand` panel
652
+
* "toggleSelection" to trigger the `onToggleItem` function
653
+
*`false` to do nothing
654
+
* a function `(id, resource, record) => path` that may return any of the above values or a custom path
655
+
656
+
**Tip**: If you pass a function, it can return `'edit'`, `'show'`, `false` or a router path. This allows to redirect to either the Edit or Show view after checking a condition on the record. For example:
You can customize the `<Datagrid>` row style (applied to the `<tr>` element) based on the record, thanks to the `rowStyle` prop, which expects a function. React-admin calls this function for each row, passing the current record and index as arguments. The function should return a style object, which react-admin uses as a `<tr style>` prop.
655
678
656
679
For instance, this allows to apply a custom background to the entire row if one value of the record - like its number of views - passes a certain threshold.
You can catch clicks on rows to redirect to the show or edit view by setting the `rowClick` prop:
698
+
You can customize the styles of rows and cells in `<Datagrid>` (applied to the `<DatagridRow>` element) based on the record, thanks to the `rowSx` prop, which expects a function. React-admin calls this function for each row, passing the current record and index as arguments. The function should return a Material UI [`sx`](https://mui.com/system/getting-started/the-sx-prop/), which react-admin uses as a `<TableRow sx>` prop.
699
+
700
+
For instance, this allows to apply a custom background to the entire row if one value of the record - like its number of views - passes a certain threshold.
* "toggleSelection" to trigger the `onToggleItem` function
695
-
*`false` to do nothing
696
-
* a function `(id, resource, record) => path` that may return any of the above values or a custom path
697
-
698
-
**Tip**: If you pass a function, it can return `'edit'`, `'show'`, `false` or a router path. This allows to redirect to either the Edit or Show view after checking a condition on the record. For example:
The `<Datagrid>` is designed for a high density of content, so the row padding is low. If you want to add more margin to each cell, set the `size` prop to `medium`.
`<SimpleList>` executes the functions passed as `primaryText`, `secondaryText`, and `tertiaryText` on render, passing the current `record` as parameter. It uses the result to render each List item.
|`primaryText`| Optional | mixed | record representation | The primary text to display. |
45
+
|`secondaryText`| Optional | mixed || The secondary text to display. |
46
+
|`tertiaryText`| Optional | mixed || The tertiary text to display. |
47
+
|`linkType`| Optional |mixed |`"edit"`| The target of each item click. |
48
+
|`leftAvatar`| Optional | function || A function returning an `<Avatar>` component to display before the primary text. |
49
+
|`leftIcon`| Optional | function || A function returning an `<Icon>` component to display before the primary text. |
50
+
|`rightAvatar`| Optional | function || A function returning an `<Avatar>` component to display after the primary text. |
51
+
|`rightIcon`| Optional | function || A function returning an `<Icon>` component to display after the primary text. |
52
+
|`rowStyle`| Optional | function || A function returning a style object to apply to each row. |
53
+
|`rowSx`| Optional | function || A function returning a sx object to apply to each row. |
54
+
|`empty`| Optional | ReactElement || A ReactElement to display instead of the list when the data is empty. |
55
+
56
+
## `empty`
57
+
58
+
It's possible that a `<SimpleList>` will have no records to display. If the `<SimpleList>`'s parent component does not handle the empty state, the `<SimpleList>` will display a message indicating there are no results. This message is translatable with the key `ra.navigation.no_results`.
59
+
60
+
You can customize the empty state by passing a component to the `empty` prop:
`<SimpleList>` creates a `RecordContext` for each list item. This allows Field components to grab the current record using [`useRecordContext`](./useRecordContext.md).
153
172
173
+
If it's **undefined**, react-admin uses the [`recordRepresentation`](./Resource.md#recordrepresentation) for the current Resource. This is the default value.
174
+
175
+
```jsx
176
+
import { List, SimpleList } from'react-admin';
177
+
178
+
exportconstPostList= () => (
179
+
<List>
180
+
<SimpleList />
181
+
</List>
182
+
);
183
+
```
184
+
154
185
## `rightAvatar`
155
186
156
187
This prop should be a function returning an `<Avatar>` component. When present, the `<ListItem>` renders a `<ListItemAvatar>` after the `<ListItemText>`
@@ -161,6 +192,8 @@ This prop should be a function returning an `<Icon>` component. When present, th
161
192
162
193
## `rowStyle`
163
194
195
+
*Deprecated - use [`rowSx`](#rowsx) instead.*
196
+
164
197
This optional prop should be a function, which gets called for each row. It receives the current record and index as arguments, and should return a style object. The style object is applied to the `<ListItem>` styles prop.
165
198
166
199
```jsx
@@ -203,24 +236,6 @@ See [`primaryText`](#primarytext)
203
236
204
237
See [`primaryText`](#primarytext)
205
238
206
-
## `empty`
207
-
208
-
It's possible that a SimpleList will have no records to display. If the SimpleList's parent component does not handle the empty state, the SimpleList will display a message indicating there are no results. This message is translatable and its key is `ra.navigation.no_results`.
209
-
210
-
You can customize the empty state by passing a component to the `empty` prop:
0 commit comments