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
When prompted, choose **JSON Server** as the data provider, then **None** as the auth provider. Do not add any resources for now and press **Enter**. Next, choose either `npm` or `yarn` and press **Enter**. Once everything is installed, run the following commands:
@@ -168,20 +168,20 @@ Copy this code and create a new `UserList` component in a new file called `users
@@ -214,16 +214,16 @@ Let's take a closer look at the `<UserList>` component:
214
214
```tsx
215
215
exportconst UserList = () => (
216
216
<List>
217
-
<Datagrid>
218
-
<TextFieldsource="id" />
219
-
<TextFieldsource="name" />
220
-
<TextFieldsource="username" />
221
-
<EmailFieldsource="email" />
222
-
<TextFieldsource="address.street" />
223
-
<TextFieldsource="phone" />
224
-
<TextFieldsource="website" />
225
-
<TextFieldsource="company.name" />
226
-
</Datagrid>
217
+
<DataTable>
218
+
<DataTable.Colsource="id" />
219
+
<DataTable.Colsource="name" />
220
+
<DataTable.Colsource="username" />
221
+
<DataTable.Colsource="email"field={EmailField} />
222
+
<DataTable.Colsource="address.street" />
223
+
<DataTable.Colsource="phone" />
224
+
<DataTable.Colsource="website" />
225
+
<DataTable.Colsource="company.name" />
226
+
</DataTable>
227
227
</List>
228
228
);
229
229
```
@@ -238,7 +238,7 @@ The root component, [`<List>`](./List.md), reads the query parameters, fetches d
238
238
239
239
This demonstrates the goal of react-admin: helping developers build sophisticated applications with simple syntax.
240
240
241
-
In most frameworks, "simple" often implies limited capabilities, making it challenging to extend beyond basic features. React-admin addresses this through *composition*. `<List>` handles data fetching, while rendering is delegated to its child—in this case, [`<Datagrid>`](./Datagrid.md). Essentially, the code composes the functionalities of `<List>` and `<Datagrid>` functionalities.
241
+
In most frameworks, "simple" often implies limited capabilities, making it challenging to extend beyond basic features. React-admin addresses this through *composition*. `<List>` handles data fetching, while rendering is delegated to its child—in this case, [`<DataTable>`](./DataTable.md). Essentially, the code composes the functionalities of `<List>` and `<DataTable>` functionalities.
242
242
243
243
This means we can compose `<List>` with another component - for instance [`<SimpleList>`](./SimpleList.md):
244
244
@@ -275,12 +275,12 @@ React-admin's layout is responsive by default. Try resizing your browser, and yo
275
275
Your browser does not support the video tag.
276
276
</video>
277
277
278
-
However, `<SimpleList>` has low information density on desktop. Let's modify `<UserList>` to use `<Datagrid>` on larger screens and `<SimpleList>` on smaller screens. We can achieve this using [Material UI's `useMediaQuery` hook](https://mui.com/material-ui/react-use-media-query/):
278
+
However, `<SimpleList>` has low information density on desktop. Let's modify `<UserList>` to use `<DataTable>` on larger screens and `<SimpleList>` on smaller screens. We can achieve this using [Material UI's `useMediaQuery` hook](https://mui.com/material-ui/react-use-media-query/):
@@ -321,22 +321,25 @@ The `<List>` component's child can be anything—even a custom component with it
321
321
322
322
## Selecting Columns
323
323
324
-
Let's get back to `<Datagrid>`. It reads the data fetched by `<List>`, then renders a table with one row for each record. `<Datagrid>` uses its child components (here, a list of [Field component](./Fields.md)) to render the columns. Each Field component renders one field of the current record, specified by the `source` prop.
324
+
Let's get back to `<DataTable>`.
325
+
It reads the data fetched by `<List>`, then renders a table with one row for each record. `<DataTable>` uses its child components (here, a list of [Field component](./Fields.md)) to render the columns.
326
+
Each `<DataTable.Col>` component renders one field of the current record, specified by the `source` prop.
325
327
326
-
`<ListGuesser>` created one column for every field in the API response. That's a bit too much for a usable grid, so let's remove a couple of `<TextField>` components from the Datagrid and see the effect:
328
+
`<ListGuesser>` created one column for every field in the API response.
329
+
That's a bit too much for a usable grid, so let's remove a couple of `<DataTable.Col>` components from the DataTable and see the effect:
@@ -345,24 +348,25 @@ In react-admin, most configuration is done through components. Instead of using
345
348
346
349
## Using Field Types
347
350
348
-
So far, you've used [`<TextField>`](./TextField.md) and [`<EmailField>`](./EmailField.md). React-admin provides [many more Field components](./Fields.md) to handle different data types—numbers, dates, images, arrays, and more.
351
+
So far, you've used simples [`<DataTable.Col>`](.//DataTable.md#datatablecol) and [`EmailField`](./EmailField.md) as [a `DataTable.Col``field`](./DataTable.md#field).
352
+
React-admin provides [many more Field components](./Fields.md) to handle different data types—numbers, dates, images, arrays, and more.
349
353
350
354
For instance, instead of displaying the `website` field as plain text, you could make it a clickable link using [`<UrlField>`](./UrlField.md):
351
355
352
356
```diff
353
357
// in src/users.tsx
354
-
-import { List, SimpleList, Datagrid, TextField, EmailField } from "react-admin";
@@ -371,9 +375,11 @@ This is typical of the early stages of development with react-admin: use a guess
371
375
372
376
## Writing A Custom Field
373
377
374
-
In react-admin, fields are just React components. When rendered, they grab the `record` fetched from the API (e.g. `{ "id": 2, "name": "Ervin Howell", "website": "anastasia.net", ... }`) using a custom hook, and use the `source` prop (e.g. `website`) to get the value they should display (e.g. "anastasia.net").
378
+
In react-admin, fields are just React components.
379
+
When rendered, they grab the `record` fetched from the API (e.g. `{ "id": 2, "name": "Ervin Howell", "website": "anastasia.net", ... }`) using a custom hook, and use the `source` prop (e.g. `website`) to get the value they should display (e.g. "anastasia.net").
375
380
376
-
That means you can do the same to [write a custom field](./Fields.md#writing-your-own-field-component). For instance, here is a simplified version of the `<UrlField>`:
381
+
That means you can do the same to [write a custom field](./Fields.md#writing-your-own-field-component).
382
+
For instance, here is a simplified version of the `<UrlField>`:
For each row, `<Datagrid>` creates a `RecordContext` and stores the current record in it. [`useRecordContext`](./useRecordContext.md) allows you to read that record. It's one of the 50+ headless hooks that react-admin exposes to let you build your own components without forcing a particular UI.
397
+
For each row, `<DataTable>` creates a `RecordContext` and stores the current record in it.
398
+
[`useRecordContext`](./useRecordContext.md) allows you to read that record.
399
+
It's one of the 50+ headless hooks that react-admin exposes to let you build your own components without forcing a particular UI.
392
400
393
401
You can use the `<MyUrlField>` component in `<UserList>` instead of react-admin's `<UrlField>` component, and it will work just the same.
This means react-admin never blocks you: if one react-admin component doesn't perfectly suit your needs, you can just swap it with your own version.
@@ -478,20 +486,23 @@ export const App = () => (
478
486
479
487
[](./img/tutorial_guessed_post_list.png)
480
488
481
-
The `ListGuesser` suggests using a [`<ReferenceField>`](./ReferenceField.md) for the `userId` field. Let's play with this new field by creating the `PostList` component based on the code dumped by the guesser:
489
+
The `ListGuesser` suggests using a [`<ReferenceField>`](./ReferenceField.md) for the `userId` field.
490
+
Let's play with this new field by creating the `PostList` component based on the code dumped by the guesser:
@@ -521,26 +532,32 @@ When displaying the posts list, react-admin is smart enough to display the `name
521
532
522
533
The `<ReferenceField>` component fetches the reference data, creates a `RecordContext` with the result, and renders the record representation (or its children).
523
534
524
-
**Tip**: Look at the network tab of your browser again: react-admin deduplicates requests for users and aggregates them in order to make only *one* HTTP request to the `/users` endpoint for the whole Datagrid. That's one of many optimizations that keep the UI fast and responsive.
535
+
**Tip**: Look at the network tab of your browser again: react-admin deduplicates requests for users and aggregates them in order to make only *one* HTTP request to the `/users` endpoint for the whole DataTable. That's one of many optimizations that keep the UI fast and responsive.
525
536
526
-
To finish the post list, place the post `id` field as the first column, and remove the `body` field. From a UX point of view, fields containing large chunks of text should not appear in a Datagrid, only in detail views. Also, to make the Edit action stand out, let's replace the default `rowClick` action with an explicit action button:
537
+
To finish the post list, place the post `id` field as the first column, and remove the `body` field.
538
+
From a UX point of view, fields containing large chunks of text should not appear in a DataTable, only in detail views.
539
+
Also, to make the Edit action stand out, let's replace the default `rowClick` action with an explicit action button:
527
540
528
541
```diff
529
542
// in src/posts.tsx
530
-
-import { List, Datagrid, TextField, ReferenceField } from "react-admin";
531
-
+import { List, Datagrid, TextField, ReferenceField, EditButton } from "react-admin";
543
+
-import { List, DataTable, ReferenceField } from "react-admin";
544
+
+import { List, DataTable, ReferenceField, EditButton } from "react-admin";
If you've understood the `<List>` component, the `<Edit>` component will be no surprise. It's responsible for fetching the record and displaying the page title. It passes the record down to the [`<SimpleForm>`](./SimpleForm.md) component, which is responsible for the form layout, default values, and validation. Just like `<Datagrid>`, `<SimpleForm>` uses its children to determine the form inputs to display. It expects [*input components*](./Inputs.md) as children. [`<TextInput>`](./TextInput.md) and [`<ReferenceInput>`](./ReferenceInput.md) are such inputs.
720
+
If you've understood the `<List>` component, the `<Edit>` component will be no surprise. It's responsible for fetching the record and displaying the page title. It passes the record down to the [`<SimpleForm>`](./SimpleForm.md) component, which is responsible for the form layout, default values, and validation. Just like `<DataTable>`, `<SimpleForm>` uses its children to determine the form inputs to display. It expects [*input components*](./Inputs.md) as children. [`<TextInput>`](./TextInput.md) and [`<ReferenceInput>`](./ReferenceInput.md) are such inputs.
703
721
704
722
The `<ReferenceInput>` takes the same props as the `<ReferenceField>` (used earlier in the `<PostList>` page). `<ReferenceInput>` uses these props to fetch the API for possible references related to the current record (in this case, possible `users` for the current `post`). It then creates a context with the possible choices and renders an [`<AutocompleteInput>`](./AutocompleteInput.md), which is responsible for displaying the choices and letting the user select one.
705
723
@@ -711,8 +729,7 @@ Let's allow users to create posts, too. Copy the `<PostEdit>` component into a `
0 commit comments