Skip to content

Commit c1e45ad

Browse files
committed
replace Datagrid by DataTable in doc - part 3
1 parent 579926b commit c1e45ad

File tree

10 files changed

+79
-70
lines changed

10 files changed

+79
-70
lines changed

docs/WithListContext.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@ The most common use case for `<WithListContext>` is to build a custom list view
1616
For instance, a list of book tags fetched via [`<ReferenceArrayField>`](./ReferenceArrayField.md):
1717

1818
```jsx
19-
import { List, Datagrid, TextField, ReferenceArrayField, WithListContext } from 'react-admin';
19+
import { List, DataTable, ReferenceArrayField, WithListContext } from 'react-admin';
2020
import { Chip, Stack } from '@mui/material';
2121

2222
const BookList = () => (
2323
<List>
24-
<Datagrid>
25-
<TextField source="id" />
26-
<TextField source="title" />
27-
<ReferenceArrayField label="Tags" reference="tags" source="tag_ids">
28-
<WithListContext render={({ isPending, data }) => (
29-
!isPending && (
30-
<Stack direction="row" spacing={1}>
31-
{data.map(tag => (
32-
<Chip key={tag.id} label={tag.name} />
33-
))}
34-
</Stack>
35-
)
36-
)} />
37-
</ReferenceArrayField>
38-
</Datagrid>
24+
<DataTable>
25+
<DataTable.Col source="id" />
26+
<DataTable.Col source="title" />
27+
<DataTable.Col source="tag_ids" label="Tags">
28+
<ReferenceArrayField reference="tags" source="tag_ids">
29+
<WithListContext render={({ isPending, data }) => (
30+
!isPending && (
31+
<Stack direction="row" spacing={1}>
32+
{data.map(tag => (
33+
<Chip key={tag.id} label={tag.name} />
34+
))}
35+
</Stack>
36+
)
37+
)} />
38+
</ReferenceArrayField>
39+
</DataTable.Col>
40+
</DataTable>
3941
</List>
4042
);
4143
```
@@ -45,17 +47,19 @@ const BookList = () => (
4547
The equivalent with `useListContext` would require an intermediate component:
4648

4749
```jsx
48-
import { List, Datagrid, TextField, ReferenceArrayField, WithListContext } from 'react-admin';
50+
import { List, DataTable, ReferenceArrayField, WithListContext } from 'react-admin';
4951

5052
const BookList = () => (
5153
<List>
52-
<Datagrid>
53-
<TextField source="id" />
54-
<TextField source="title" />
55-
<ReferenceArrayField label="Tags" reference="tags" source="tag_ids">
56-
<TagList />
57-
</ReferenceArrayField>
58-
</Datagrid>
54+
<DataTable>
55+
<DataTable.Col source="id" />
56+
<DataTable.Col source="title" />
57+
<DataTable.Col label="Tags" source="tag_ids">
58+
<ReferenceArrayField reference="tags" source="tag_ids">
59+
<TagList />
60+
</ReferenceArrayField>
61+
</DataTable.Col>
62+
</DataTable>
5963
</List>
6064
);
6165

docs/WithRecord.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,26 @@ As soon as there is a record available, react-admin puts it in a `RecordContext`
3232
- in descendants of the `<Show>` and `<ShowBase>` component
3333
- in descendants of the `<Edit>` and `<EditBase>` component
3434
- in descendants of the `<Create>` and `<CreateBase>` component
35+
- in descendants of the `<DataTable>` component
3536
- in descendants of the `<Datagrid>` component
3637
- in descendants of the `<SimpleList>` component
3738
- in descendants of the `<ReferenceField>` component
3839

39-
## Using in a Datagrid
40+
## Using in a DataTable
4041

41-
When using `<WithRecord>` in a [`<Datagrid>`](./Datagrid.md), you must specify the `label` prop to let react-admin know which field to display in the column header.
42+
When using `<WithRecord>` in a [`<DataTable>`](./DataTable.md), you must specify the `label` prop to let react-admin know which field to display in the column header.
4243

4344
```jsx
44-
import { Datagrid, TextField, WithRecord } from 'react-admin';
45+
import { DataTable, WithRecord } from 'react-admin';
4546

4647
const PostList = () => (
4748
<List>
48-
<Datagrid>
49-
<TextField source="title" />
50-
<WithRecord label="author" render={record => <span>{record.author}</span>} />
51-
</Datagrid>
49+
<DataTable>
50+
<DataTable.Col source="title" />
51+
<DataTable.Col label="author">
52+
<WithRecord render={record => <span>{record.author}</span>} />
53+
</DataTable.Col>
54+
</DataTable>
5255
</List>
5356
);
5457
```

docs/useListContext.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The `ListContext` is available to descendants of:
1515
- `<ReferenceArrayField>`,
1616
- `<ReferenceManyField>`
1717

18-
All descendant components can therefore access the list context, using the `useListContext` hook. As a matter of fact, react-admin's `<Datagrid>`, `<FilterForm>`, and `<Pagination>` components all use the `useListContext` hook.
18+
All descendant components can therefore access the list context, using the `useListContext` hook. As a matter of fact, react-admin's `<DataTable>`, `<FilterForm>`, and `<Pagination>` components all use the `useListContext` hook.
1919

2020
## Usage
2121

@@ -40,16 +40,16 @@ export const Aside = () => {
4040
};
4141

4242
// in src/posts/PostList.js
43-
import { List, Datagrid, TextField } from 'react-admin';
43+
import { List, DataTable } from 'react-admin';
4444
import Aside from './Aside';
4545

4646
export const PostList = () => (
4747
<List aside={<Aside />}>
48-
<Datagrid>
49-
<TextField source="id" />
50-
<TextField source="title" />
51-
<TextField source="views" />
52-
</Datagrid>
48+
<DataTable>
49+
<DataTable.Col source="id" />
50+
<DataTable.Col source="title" />
51+
<DataTable.Col source="views" />
52+
</DataTable>
5353
</List>
5454
);
5555
```
@@ -163,7 +163,7 @@ The `useListContext` hook accepts a generic parameter for the record type:
163163

164164
```tsx
165165
import { Typography } from '@mui/material';
166-
import { List, Datagrid, TextField, useListContext } from 'react-admin';
166+
import { List, DataTable, useListContext } from 'react-admin';
167167

168168
type Post = {
169169
id: number;
@@ -187,11 +187,11 @@ export const Aside = () => {
187187

188188
export const PostList = () => (
189189
<List aside={<Aside />}>
190-
<Datagrid>
191-
<TextField source="id" />
192-
<TextField source="title" />
193-
<TextField source="views" />
194-
</Datagrid>
190+
<DataTable>
191+
<DataTable.Col source="id" />
192+
<DataTable.Col source="title" />
193+
<DataTable.Col source="views" />
194+
</DataTable>
195195
</List>
196196
);
197197
```
@@ -208,4 +208,4 @@ You can find many usage examples of `useListContext` in the documentation, inclu
208208
- [Building a Custom Pagination Control](./ListTutorial.md#building-a-custom-pagination)
209209
- [Building a Custom Iterator](./ListTutorial.md#building-a-custom-iterator)
210210

211-
**Tip**: [`<ReferenceManyField>`](./ReferenceManyField.md), as well as other relationship-related components, also implement a `ListContext`. That means you can use a `<Datagrid>` of a `<Pagination>` inside these components!
211+
**Tip**: [`<ReferenceManyField>`](./ReferenceManyField.md), as well as other relationship-related components, also implement a `ListContext`. That means you can use a `<DataTable>` of a `<Pagination>` inside these components!

docs/useListController.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ title: "useListController"
1111

1212
`useListController` reads the list parameters from the URL, calls `dataProvider.getList()`, prepares callbacks for modifying the pagination, filters, sort and selection, and returns them together with the data. Its return value matches the [`ListContext`](./useListContext.md) shape.
1313

14-
`useListController` is used internally by [`<List>`](./List.md) and [`<ListBase>`](./ListBase.md). If your list view uses react-admin components like [`<Datagrid>`](./Datagrid.md), prefer [`<ListBase>`](./ListBase.md) to `useListController` as it takes care of creating a `<ListContext>`.
14+
`useListController` is used internally by [`<List>`](./List.md) and [`<ListBase>`](./ListBase.md). If your list view uses react-admin components like [`<DataTable>`](./DataTable.md), prefer [`<ListBase>`](./ListBase.md) to `useListController` as it takes care of creating a `<ListContext>`.
1515

1616
## Usage
1717

docs/useMediaQuery.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ const isSmall = useMediaQuery('(min-width:600px)');
2727

2828
## Responsive Layouts
2929

30-
Here is an example for a responsive list of posts, displaying a `SimpleList` on mobile, and a `Datagrid` otherwise:
30+
Here is an example for a responsive list of posts, displaying a `SimpleList` on mobile, and a `DataTable` otherwise:
3131

3232
```jsx
3333
// in src/posts.js
3434
import * as React from 'react';
3535
import { useMediaQuery } from '@mui/material';
36-
import { List, SimpleList, Datagrid, TextField, ReferenceField, EditButton } from 'react-admin';
36+
import { List, SimpleList, DataTable, ReferenceField, EditButton } from 'react-admin';
3737

3838
export const PostList = () => {
3939
const isSmall = useMediaQuery(
@@ -49,15 +49,17 @@ export const PostList = () => {
4949
tertiaryText={record => new Date(record.published_at).toLocaleDateString()}
5050
/>
5151
) : (
52-
<Datagrid>
53-
<TextField source="id" />
54-
<ReferenceField label="User" source="userId" reference="users">
55-
<TextField source="name" />
56-
</ReferenceField>
57-
<TextField source="title" />
58-
<TextField source="body" />
59-
<EditButton />
60-
</Datagrid>
52+
<DataTable>
53+
<DataTable.Col source="id" />
54+
<DataTable.Col label="User" source="userId">
55+
<ReferenceField source="userId" reference="users">
56+
<TextField source="name" />
57+
</ReferenceField>
58+
</DataTable.Col>
59+
<DataTable.Col source="title" />
60+
<DataTable.Col source="body" />
61+
<DataTable.Col field={EditButton} />
62+
</DataTable>
6163
)}
6264
</List>
6365
);

docs/useRecordContext.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: "useRecordContext"
55

66
# `useRecordContext`
77

8-
`useRecordContext` grabs the current record. It's available anywhere react-admin manipulates a record, e.g. in a Show page, in a Datagrid row, or in a Reference Field.
8+
`useRecordContext` grabs the current record. It's available anywhere react-admin manipulates a record, e.g. in a Show page, in a DataTable row, or in a Reference Field.
99

1010
<iframe src="https://www.youtube-nocookie.com/embed/YLwx-EZfGFk" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen style="aspect-ratio: 16 / 9;width:100%;margin-bottom:1em;"></iframe>
1111

@@ -58,7 +58,7 @@ As soon as there is a record available, react-admin puts it in a `RecordContext`
5858
- in descendants of the `<Show>` and `<ShowBase>` component
5959
- in descendants of the `<Edit>` and `<EditBase>` component
6060
- in descendants of the `<Create>` and `<CreateBase>` component
61-
- in descendants of the `<Datagrid>` component
61+
- in descendants of the `<DataTable>` component
6262
- in descendants of the `<SimpleList>` component
6363
- in descendants of the `<ReferenceField>` component
6464

docs/useStore.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ When one component calls `setValue` on a key, all the components that read the s
3333
## Example
3434

3535
```jsx
36-
import { List, Datagrid } from 'react-admin';
36+
import { List, DataTable } from 'react-admin';
3737

3838
const PostList = () => {
3939
const [density] = useStore('posts.list.density', 'small');
4040

4141
return (
4242
<List>
43-
<Datagrid size={density}>
43+
<DataTable size={density}>
4444
...
45-
</Datagrid>
45+
</DataTable>
4646
</List>
4747
);
4848
}

docs/useSubscribeToRecordList.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ const ListWatcher = () => {
5656

5757
const MovieList = () => (
5858
<List>
59-
<Datagrid>
60-
<TextField source="id" />
61-
<TextField source="title" />
62-
<TextField source="director" />
63-
<TextField source="year" />
64-
</Datagrid>
59+
<DataTable>
60+
<DataTable.Col source="id" />
61+
<DataTable.Col source="title" />
62+
<DataTable.Col source="director" />
63+
<DataTable.Col source="year" />
64+
</DataTable>
6565
<ListWatcher />
6666
</List>
6767
);

docs/useUnselect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: "useUnselect"
55

66
# `useUnselect`
77

8-
This hook returns a function that unselects lines in the current `<Datagrid>` that match an array of ids. Pass the name of the resource to the hook as argument.
8+
This hook returns a function that unselects lines in the current `<DataTable>` that match an array of ids. Pass the name of the resource to the hook as argument.
99

1010
```jsx
1111
import { useListContext, useUnselect } from 'react-admin';

docs/useUnselectAll.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: "useUnselectAll"
55

66
# `useUnselectAll`
77

8-
This hook returns a function that unselects all lines in the current `<Datagrid>`. Pass the name of the resource as argument.
8+
This hook returns a function that unselects all lines in the current `<DataTable>`. Pass the name of the resource as argument.
99

1010
```jsx
1111
import { useUnselectAll } from 'react-admin';

0 commit comments

Comments
 (0)