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
@@ -168,13 +169,14 @@ You can use the `filter` prop to display only a subset of the items in the array
168
169
</DataTable>
169
170
</ArrayField>
170
171
```
172
+
171
173
{% endraw %}
172
174
173
175
The filtering capabilities are very limited. For instance, there is no "greater than" or "less than" operator. You can only filter on the equality of a field.
174
176
175
177
## `perPage`
176
178
177
-
If the value is a large array, and you don't need to display all the items, you can use the `perPage` prop to limit the number of items displayed.
179
+
If the value is a large array, and you don't need to display all the items, you can use the `perPage` prop to limit the number of items displayed.
178
180
179
181
As `<ArrayField>` creates a [`ListContext`](./useListContext.md), you can use the `<Pagination>` component to navigate through the items.
180
182
@@ -210,13 +212,15 @@ const PostShow = () => (
210
212
By default, `<ArrayField>` displays the items in the order they are stored in the field. You can use the `sort` prop to change the sort order.
`<ReferenceManyField>` is useful for displaying a list of related records via a one-to-many relationship, when the foreign key is carried by the referenced resource.
9
+
`<ReferenceManyField>` is useful for displaying a list of related records via a one-to-many relationship, when the foreign key is carried by the referenced resource.
@@ -97,7 +97,7 @@ This example leverages [`<SingleFieldList>`](./SingleFieldList.md) to display an
97
97
|`empty`| Optional |`ReactNode`| - | Element to display when there are no related records. |
98
98
|`error`| Optional |`ReactNode`| - | The component to render when an error occurs while fetching the related records |
99
99
|`filter`| Optional |`Object`| - | Filters to use when fetching the related records, passed to `getManyReference()`|
100
-
|`exporter`| Optional |`function`|`defaultExporter`| The function called by export buttons in the list context |
100
+
|`exporter`| Optional |`function`|`default Exporter`| The function called by export buttons in the list context |
101
101
|`loading`| Optional |`ReactNode`| - | The component to render while fetching the related records |
102
102
|`offline`| Optional |`ReactNode`| - | Element to display when there are no related records because of lack of network connectivity. |
103
103
|`pagination`| Optional |`Element`| - | Pagination element to display pagination controls. empty by default (no pagination) |
@@ -121,7 +121,7 @@ This example leverages [`<SingleFieldList>`](./SingleFieldList.md) to display an
121
121
-[`<SimpleList>`](./SimpleList.md)
122
122
-[`<EditableDatagrid>`](./EditableDatagrid.md)
123
123
-[`<Calendar>`](./Calendar.md)
124
-
- Or a component of your own (check the [`<WithListContext>`](./WithListContext.md) and the [`useListContext`](./useListContext.md) chapters to learn how).
124
+
- Or a component of your own (check the [`<WithListContext>`](./WithListContext.md) and the [`useListContext`](./useListContext.md) chapters to learn how).
125
125
126
126
For instance, use a `<DataTable>` to render the related records in a table:
127
127
@@ -452,9 +452,11 @@ Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` que
452
452
For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
@@ -506,6 +508,7 @@ This allows to inline the render logic for the list of related records.
506
508
By default, it orders the possible values by id desc. You can change this order by setting the `sort` prop (an object with `field` and `order` properties).
507
509
508
510
{% raw %}
511
+
509
512
```jsx
510
513
<ReferenceManyField
511
514
target="post_id"
@@ -515,6 +518,7 @@ By default, it orders the possible values by id desc. You can change this order
515
518
...
516
519
</ReferenceManyField>
517
520
```
521
+
518
522
{% endraw %}
519
523
520
524
## `source`
@@ -540,6 +544,7 @@ If you want to display multiple lists of the same reference and keep distinct se
540
544
In the example below, both lists use the same reference ('books'), but their selection states are stored separately (under the store keys `'authors.1.books.selectedIds'` and `'custom.selectedIds'` respectively). This allows to use both components in the same page, each having its own state.
541
545
542
546
{% raw %}
547
+
543
548
```jsx
544
549
<Stack direction="row" spacing={2}>
545
550
<ReferenceManyField
@@ -567,6 +572,7 @@ In the example below, both lists use the same reference ('books'), but their sel
567
572
</ReferenceManyField>
568
573
</Stack>
569
574
```
575
+
570
576
{% endraw %}
571
577
572
578
## `target`
@@ -584,11 +590,12 @@ Name of the field carrying the relationship on the referenced resource. For inst
584
590
585
591
## Rendering Only One Record
586
592
587
-
Although you are in a one-to-many relationship, you may want to render only one record. For instance, in a book with several reviews, you may want to display only the last. Or, for a product with many prices, you may want to display only the one in euros.
593
+
Although you are in a one-to-many relationship, you may want to render only one record. For instance, in a book with several reviews, you may want to display only the last. Or, for a product with many prices, you may want to display only the one in euros.
588
594
589
595
In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md) instead of `<ReferenceManyField>`.
590
596
591
597
{% raw %}
598
+
592
599
```jsx
593
600
<ReferenceOneField
594
601
label="Latest review"
@@ -600,9 +607,11 @@ In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md
600
607
<TextField source="body"/>
601
608
</ReferenceOneField>
602
609
```
610
+
603
611
{% endraw %}
604
612
605
613
{% raw %}
614
+
606
615
```jsx
607
616
<ReferenceOneField
608
617
label="Price (€)"
@@ -613,6 +622,7 @@ In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md
613
622
<NumberField source="price"/>
614
623
</ReferenceOneField>
615
624
```
625
+
616
626
{% endraw %}
617
627
618
628
## Adding or editing a related record
@@ -625,6 +635,7 @@ To allow users to create or edit a record without leaving the current view, use
`useListController` contains the headless logic of the [`<List>`](./List.md) component. It's useful to create a custom List view. It's also the base hook when building a custom view with another UI kit than Material UI.
9
+
`useListController` contains the headless logic of the [`<List>`](./List.md) component. It's useful to create a custom List view. It's also the base hook when building a custom view with another UI kit than Material UI.
10
10
11
11

12
12
13
-
`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.
13
+
`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.
14
14
15
15
`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>`.
Here the code for the post list view above, built with [Ant Design](https://ant.design/):
22
22
23
23
{% raw %}
24
+
24
25
```jsx
25
26
import { useListController } from'react-admin';
26
27
import { Card, Table, Button } from'antd';
@@ -86,6 +87,7 @@ const columns = [
86
87
87
88
exportdefaultPostList;
88
89
```
90
+
89
91
{% endraw %}
90
92
91
93
When using react-admin components, it's common to call `useListController()` without parameters, and to put the result in a `ListContext` to make it available to the rest of the component tree.
@@ -110,17 +112,21 @@ const MyList = () => {
110
112
111
113
`useListController` expects an object as parameter. All keys are optional.
112
114
113
-
*[`debounce`](./List.md#debounce): Debounce time in ms for the setFilters callbacks
114
-
*[`disableAuthentication`](./List.md#disableauthentication): Set to true to allow anonymous access to the list
115
-
*[`disableSyncWithLocation`](./List.md#disablesyncwithlocation): Set to true to have more than one list per page
116
-
*[`exporter`](./List.md#exporter): Exporter function
117
-
*[`filter`](./List.md#filter-permanent-filter): Permanent filter, forced over the user filter
118
-
*[`filterDefaultValues`](./List.md#filterdefaultvalues): Default values for the filter form
119
-
*[`perPage`](./List.md#perpage): Number of results per page
120
-
*[`queryOptions`](./List.md#queryoptions): React-query options for the useQuery call
121
-
*[`resource`](./List.md#resource): Resource name, e.g. 'posts' ; defaults to the current resource context
122
-
*[`sort`](./List.md#sort): Current sort value, e.g. `{ field: 'published_at', order: 'DESC' }`
123
-
*[`storeKey`](#storekey): Key used to differentiate the list from another sharing the same resource, in store managed states
|`debounce`|`number`|`500`| The debounce delay in milliseconds to apply when users change the sort or filter parameters. |
118
+
|`disableAuthentication`|`boolean`|`false`| Set to `true` to disable the authentication check. |
119
+
|`disableSyncWithLocation`|`boolean`|`false`| Set to `true` to disable the synchronization of the list parameters with the URL. |
120
+
|`exporter`|`function`| - | The function to call to export the list. |
121
+
|`filter`|`object`| - | The permanent filter values, forced over the user filter |
122
+
|`filterDefaultValues`|`object`| - | The default filter values. |
123
+
|`perPage`|`number`|`10`| The number of records to fetch per page. |
124
+
|`queryOptions`|`object`| - | The options to pass to the `useQuery` hook. |
125
+
|`resource`|`string`| - | The resource name, e.g. `posts`. |
126
+
|`sort`|`object`| - | The initial sort parameters, e.g. `{ field: 'published_at', order: 'DESC' }`. |
127
+
|`storeKey`|`string`|`false`| - | The key to use to store the current filter & sort. Pass `false` to disable store synchronization |
128
+
129
+
Check [the `<List>` component documentation](./List.md) for more details about these parameters.
124
130
125
131
Here are their default values:
126
132
@@ -178,6 +184,7 @@ If you want to disable the storage of list parameters altogether for a given lis
178
184
In the example below, both lists `TopPosts` and `FlopPosts` use the same resource ('posts'), but their controller states are stored separately (under the store keys `'top'` and `'flop'` respectively).
0 commit comments