Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show header row for empty Datagrids #6087

Closed
JoeJErnst opened this issue Mar 26, 2021 · 3 comments
Closed

Show header row for empty Datagrids #6087

JoeJErnst opened this issue Mar 26, 2021 · 3 comments

Comments

@JoeJErnst
Copy link

Is your feature request related to a problem? Please describe.
I don't understand why the decision was made to return null for the whole Datagrid if there are no rows to return. I would expect to still see the header row.

Describe the solution you'd like
Offer a property that allows me to specify whether or not to hide empty Datagrids.

Describe alternatives you've considered
It could be a boolean hideWhenEmpty (default to true for backwards compatibility).

Additional context

if (loaded && (ids.length === 0 || total === 0)) {

@fzaninotto
Copy link
Member

The <List> component exposes an empty prop exactly for this use case.

https://marmelab.com/react-admin/List.html#empty-empty-page-component

@JoeJErnst
Copy link
Author

The empty prop on the <List> component is far too restrictive for this use case, for three separate reasons:

  1. It only works if there's NOT an active filter
  2. It only works if there's a create page for the resource
  3. It still won't show the column headers

I have several Datagrids in my app that will have default filters enabled, and no create page. I still need my users to see that there's an empty grid, not no grid at all. There is value in seeing what the columns are, even if no data exists.

I feel this should be true in general, not just because my app has special requirements. I stand by my enhancement request for the Datagrid component. I'll see if I can get a pull request put together with my suggested implementation, in case you want to reconsider.

@fzaninotto
Copy link
Member

I disagree that showing a header line with no body is better in general, but I understand that it may be better in some cases.

About your points:

  1. Right, the empty page is designed as the initial state, not for displaying an empty filtered list
  2. no, the <List empty> component displays even though there is no create page
  3. it's up to you to pass the component of your choice to display just a list of headers in this case

Also, the <Datagrid> could accept an empty prop to display a custom component instead of null when the list is empty because the filters are too narrow. We can accept a PR for that (and I think it's trivial).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants