Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,12 +1190,27 @@ export const PostList = () => (
}
}}
>
{/* DataGrid */}
<WithListContext
render={context =>
context.filterValues.q == null ||
context.filterValues.q === '' ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too bad you copied the wrong condition: in the docs the condition was q.length > 2 and not q !== '' 😅

<CardContentInner>
Type a search term to fetch data
</CardContentInner>
) : (
<Datagrid>
{/* your fields */}
</Datagrid>
)
}
/>
</List>
)
```
{% endraw %}

**Note**: Notice we display some custom UI when there is no filter. This is because otherwise, users would see the loading UI as Tanstack Query will set the `isPending` property of the underlying query to `true` if the query isn't enabled.

## Accessing Extra Response Data

If `dataProvider.getList()` returns additional metadata in the response under the `meta` key, you can access it in the list view using the `meta` property of the `ListContext`.
Expand Down
28 changes: 13 additions & 15 deletions packages/ra-ui-materialui/src/list/List.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TestMemoryRouter,
DataProvider,
GetListParams,
WithListContext,
} from 'ra-core';
import fakeRestDataProvider from 'ra-data-fakerest';
import {
Expand Down Expand Up @@ -253,28 +254,25 @@ export const ConditionalDataFetching = () => (
},
}}
>
<ConditionalDataFetchingView />
<WithListContext
render={context =>
context.filterValues.q == null ||
context.filterValues.q === '' ? (
<CardContentInner>
Type a search term to fetch data
</CardContentInner>
) : (
<BookList />
)
}
/>
</List>
)}
/>
</Admin>
</TestMemoryRouter>
);

const ConditionalDataFetchingView = () => {
const context = useListContext();

if (context.filterValues.q == null || context.filterValues.q === '') {
return (
<CardContentInner>
Type a search term to fetch data
</CardContentInner>
);
}

return <BookList />;
};

export const Filter = () => (
<TestMemoryRouter initialEntries={['/books']}>
<Admin dataProvider={defaultDataProvider}>
Expand Down
Loading