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
@@ -167,13 +169,14 @@ You can use the `filter` prop to display only a subset of the items in the array
167
169
</DataTable>
168
170
</ArrayField>
169
171
```
172
+
170
173
{% endraw %}
171
174
172
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.
173
176
174
177
## `perPage`
175
178
176
-
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.
177
180
178
181
As `<ArrayField>` creates a [`ListContext`](./useListContext.md), you can use the `<Pagination>` component to navigate through the items.
179
182
@@ -209,13 +212,15 @@ const PostShow = () => (
209
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.
Copy file name to clipboardExpand all lines: docs/ReferenceArrayField.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,7 @@ You can change how the list of related records is rendered by passing a custom c
90
90
|`empty`| Optional |`ReactNode`| - | The component to render when the related records list is empty |
91
91
|`error`| Optional |`ReactNode`| - | The component to render when an error occurs while fetching the related records |
92
92
|`filter`| Optional |`Object`| - | Filters to use when fetching the related records (the filtering is done client-side) |
93
+
|`exporter`| Optional |`function`|`defaultExporter`| The function called by export buttons in the list context |
93
94
|`loading`| Optional |`ReactNode`|`<LinearProgress>`| The component to render while fetching the related records |
94
95
|`offline`| Optional |`ReactNode`|`<Offline variant="inline" />`| The component to render when there is no connectivity and the record isn't in the cache |
95
96
|`pagination`| Optional |`ReactNode`| - | Pagination element to display pagination controls. empty by default (no pagination) |
`<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,6 +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`|`default Exporter`| The function called by export buttons in the list context |
100
101
|`loading`| Optional |`ReactNode`| - | The component to render while fetching the related records |
101
102
|`offline`| Optional |`ReactNode`| - | Element to display when there are no related records because of lack of network connectivity. |
102
103
|`pagination`| Optional |`Element`| - | Pagination element to display pagination controls. empty by default (no pagination) |
@@ -120,7 +121,7 @@ This example leverages [`<SingleFieldList>`](./SingleFieldList.md) to display an
120
121
-[`<SimpleList>`](./SimpleList.md)
121
122
-[`<EditableDatagrid>`](./EditableDatagrid.md)
122
123
-[`<Calendar>`](./Calendar.md)
123
-
- 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).
124
125
125
126
For instance, use a `<DataTable>` to render the related records in a table:
126
127
@@ -451,9 +452,11 @@ Use the `queryOptions` prop to pass options to [the `dataProvider.getMany()` que
451
452
For instance, to pass [a custom `meta`](./Actions.md#meta-parameter):
@@ -505,6 +508,7 @@ This allows to inline the render logic for the list of related records.
505
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).
506
509
507
510
{% raw %}
511
+
508
512
```jsx
509
513
<ReferenceManyField
510
514
target="post_id"
@@ -514,6 +518,7 @@ By default, it orders the possible values by id desc. You can change this order
514
518
...
515
519
</ReferenceManyField>
516
520
```
521
+
517
522
{% endraw %}
518
523
519
524
## `source`
@@ -539,6 +544,7 @@ If you want to display multiple lists of the same reference and keep distinct se
539
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.
540
545
541
546
{% raw %}
547
+
542
548
```jsx
543
549
<Stack direction="row" spacing={2}>
544
550
<ReferenceManyField
@@ -566,6 +572,7 @@ In the example below, both lists use the same reference ('books'), but their sel
566
572
</ReferenceManyField>
567
573
</Stack>
568
574
```
575
+
569
576
{% endraw %}
570
577
571
578
## `target`
@@ -583,11 +590,12 @@ Name of the field carrying the relationship on the referenced resource. For inst
583
590
584
591
## Rendering Only One Record
585
592
586
-
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.
587
594
588
595
In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md) instead of `<ReferenceManyField>`.
589
596
590
597
{% raw %}
598
+
591
599
```jsx
592
600
<ReferenceOneField
593
601
label="Latest review"
@@ -599,9 +607,11 @@ In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md
599
607
<TextField source="body"/>
600
608
</ReferenceOneField>
601
609
```
610
+
602
611
{% endraw %}
603
612
604
613
{% raw %}
614
+
605
615
```jsx
606
616
<ReferenceOneField
607
617
label="Price (€)"
@@ -612,6 +622,7 @@ In these cases, use [the `<ReferenceOneField>` component](./ReferenceOneField.md
612
622
<NumberField source="price"/>
613
623
</ReferenceOneField>
614
624
```
625
+
615
626
{% endraw %}
616
627
617
628
## Adding or editing a related record
@@ -624,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