Skip to content

Commit

Permalink
Merge pull request #10467 from marmelab/doc/live_filtering_refM2Mfiel…
Browse files Browse the repository at this point in the history
…d_refMfield

[Doc] Document live filtering with `ReferenceManyField` and `ReferenceManyToManyField`
  • Loading branch information
djhi authored Jan 24, 2025
2 parents 443fb60 + 246152f commit ebbb860
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
35 changes: 34 additions & 1 deletion docs/ReferenceManyField.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ const PostCommentsField = () => (
);
```

## `filter`
## `filter`: Permanent Filter

You can filter the query used to populate the possible values. Use the `filter` prop for that.

{% raw %}

```jsx
<ReferenceManyField
reference="comments"
Expand All @@ -185,6 +186,38 @@ You can filter the query used to populate the possible values. Use the `filter`
...
</ReferenceManyField>
```

{% endraw %}

## Filtering The References

<video controls autoplay playsinline muted loop>
<source src="./img/ReferenceManyFieldFilterInput.mp4" type="video/mp4" />
Your browser does not support the video tag.
</video>

You can add filters to `<ReferenceManyField>` by adding [`<FilterForm>`](./FilterForm.md) and [`<FilterButton>`](./FilterButton.md):

{% raw %}

```jsx
const filters = [<TextInput source="q" label="Search" />];

const AuthorEdit = () => (
<Edit>
<SimpleForm>
<ReferenceManyField reference="comments" target="post_id">
<FilterButton filters={filters}/>
<FilterForm filters={filters}/>
<Datagrid>
...
</Datagrid>
</ReferenceManyField>
</SimpleForm>
</Edit>
);
```

{% endraw %}

## `label`
Expand Down
Binary file added docs/img/ReferenceManyFieldFilterInput.mp4
Binary file not shown.
14 changes: 10 additions & 4 deletions packages/ra-ui-materialui/src/field/ReferenceManyField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import englishMessages from 'ra-language-english';
import { TextField } from '../field';
import { ReferenceManyField } from './ReferenceManyField';
import { Datagrid } from '../list/datagrid/Datagrid';
import { BulkActionsToolbar, Pagination, SingleFieldList } from '../list';
import {
BulkActionsToolbar,
FilterButton,
Pagination,
SingleFieldList,
} from '../list';
import { Notification } from '../layout/Notification';
import { FilterForm } from '../list';
import { TextInput } from '../input';
Expand Down Expand Up @@ -128,12 +133,13 @@ export const WithSingleFieldList = () => (
</Wrapper>
);

const filters = [<TextInput source="q" label="Search" />];

export const WithFilter = () => (
<Wrapper>
<ReferenceManyField reference="books" target="author_id">
<FilterForm
filters={[<TextInput source="q" label="Search" alwaysOn />]}
/>
<FilterButton filters={filters} />
<FilterForm filters={filters} />
<Datagrid bulkActionButtons={false}>
<TextField source="title" />
</Datagrid>
Expand Down

0 comments on commit ebbb860

Please sign in to comment.