vaadin / web-components

A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
https://vaadin.com/docs/latest/components
473 stars 83 forks source link

[grid] Provide readonly mode for grid, allowing only certain functionalities #5734

Open stefanuebe opened 1 year ago

stefanuebe commented 1 year ago

Describe your motivation

Follow up ticket of https://github.com/vaadin/web-components/issues/5719. Also not sure if this could/would be a flow-component ticket.

Currently it is not easily possible to provide a readonly grid, that allows presenting data, but not modify anything with interaction. Therefore it should be possible to mark a grid as "readonly", so that the contained data is presented, scrollable and text selectable (via cursor), but have anything else disabled.

Describe the solution you'd like

A readonly grid should provide a dedicated style as our other components to.

Also it should automatically disable certain functions to make developer lives easier.

Disabled functionalities:

Enabled functionalities:

Describe alternatives you've considered

Doing all the styling and disabling myself. Not the best DX #ffs

Additional context

No response

rolfsmeds commented 1 year ago

Although we could add a convenience method for toggling these specific features, you can already today do that with separate methods for each feature (showing Flow example here):

grid.setSelectionMode(SelectionMode.NONE);
grid.setRowsDraggable(false);
grid.setColumnReorderingAllowed(false);
// and for individual columns
someColumn.setSortable(false);
someColumn.setResizable(false);

The exception is clicklisteners (assuming you mean custom clicklisteners), but those would probably make sense to handle in the logic of the clicklisteners themseleves, as very much it depends on the listener whether what it does can be considered "editing".

For GridPro there are a couple of feature tickets about toggling the editability: https://github.com/vaadin/web-components/issues/3464 and https://github.com/vaadin/web-components/issues/985.

TatuLund commented 6 months ago

Just for the record Grid#setReadOnly was added in Vaadin 8.22.0.