-
Notifications
You must be signed in to change notification settings - Fork 83
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
feat: add slot for empty state content #7429
Conversation
Quality Gate passedIssues Measures |
The empty state is currently shown even when the grid is loading. Depending on the content, this can be misleading if loading takes a while. For example: Screen.Recording.2024-05-21.at.16.27.19.mov |
I assume this is one of the cases that will be fixed by:
|
After some internal planning, we decided to keep the current slot approach as the only API for empty content for now (a renderer function is possible to add later if necessary). Here's an example (React) of how you might dynamically change the content of your empty state slot: type Item = {
name: string;
};
export default function () {
const [loading, setLoading] = useState(false);
const [emptyItems, setEmptyItems] = useState(false);
const [dataProvider, setDataProvider] = useState<GridDataProvider<Item> | null>(null);
const lazyDataProvider: GridDataProvider<Item> = useCallback((_, callback) => {
// Return no items after a delay
setTimeout(() => {
const items: Item[] = [];
callback(items, items.length);
setEmptyItems(items.length === 0);
}, 2000);
}, []);
let emptyStateContent = null;
if (!dataProvider) {
emptyStateContent = <div>No data provider</div>;
} else if (loading) {
emptyStateContent = <div>Loading...</div>;
} else if (emptyItems) {
emptyStateContent = <div>No items</div>;
}
return (
<>
<Grid itemIdPath="name" dataProvider={dataProvider} onLoadingChanged={(e) => setLoading(e.detail.value)}>
<GridColumn path="name" width="200px" footer={'Footer'} />
<GridColumn path="name" width="200px" footer={'Footer'} />
<div slot="empty-state">{emptyStateContent}</div>
</Grid>
<Button
onClick={() => {
setDataProvider(() => lazyDataProvider);
}}
>
Set data provider
</Button>
</>
);
} Kapture.2024-05-23.at.15.28.13.mp4 |
This ticket/PR has been released with Vaadin 24.5.0.alpha1 and is also targeting the upcoming stable 24.5.0 version. |
Description
Add support for slotting grid empty state content, which will be displayed when there are no body rows to show otherwise.
Part of vaadin/platform#5719
To be implemented separately:
__showEmptyState
into a public readonlyemptyState
(naming tbd) property that reflects as an attribute and notifies on changeExample:
Kapture.2024-05-20.at.15.48.30.mp4
Type of change
Feature