Vaadin-grid: Add an empty state template (data source is empty)

Created on 25 Jan 2017  路  7Comments  路  Source: vaadin/vaadin-grid

It would be a nice feature to add an empty state template to the grid (same way as the row details) for when the data source is empty

UX finding enhancement

Most helpful comment

Reopened because this is quite highly requested feature and we might consider implementing it in the component.

All 7 comments

Related issue in Framework Grid: https://github.com/vaadin/framework/issues/9070

Grid without an empty state template really look ugly and hamper overall user experience.

Want to know if there is any plan to implement this in the future.

There is now a cookbook example for GridFlow: https://cookbook.vaadin.com/grid-message-when-empty

excellent, thanks!

Reopened because this is quite highly requested feature and we might consider implementing it in the component.

A separate message for when there IS data, but the current filters filter out everything, would be useful as well.

It's a bit of a hack but this worked for me:

In this case, the grid data is coming from this.keysArr and the vaadin-grid has id grid

grid() {
    //@ts-ignore
    return (this.root || this.shadowRoot).getElementById('grid')
}

updated(_changedProperties: any) {
    if (this.keysArr.length == 0) {
        if (this?.grid()?.shadowRoot) {
            //remove the empty state if it already exists
            if (this?.grid()?.shadowRoot?.querySelector('.emptystate')) this.grid().shadowRoot.querySelector('.emptystate').remove()
            //add the empty state to the table
            this.grid().shadowRoot.querySelector('tbody').insertAdjacentHTML('beforebegin', `
            <div class="emptystate" style="display:flex;height:100%;width:100%">
                <p style="margin:auto;font-weight:700;">No License Keys Provisioned.</p>
            </div>
            `);
        }
    }
}

Result:

image

I may add an arrow pointing to the button on the bottom later on.

Hope that helps!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Springrbua picture Springrbua  路  4Comments

suma-nunna picture suma-nunna  路  4Comments

pdesjardins90 picture pdesjardins90  路  4Comments

tomivirkki picture tomivirkki  路  3Comments

SenerDemiral picture SenerDemiral  路  3Comments