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

[DataGrid] Support inline editing #1159

Closed
glebfox opened this issue Nov 1, 2022 · 0 comments
Closed

[DataGrid] Support inline editing #1159

glebfox opened this issue Nov 1, 2022 · 0 comments
Assignees
Projects
Milestone

Comments

@glebfox
Copy link
Contributor

glebfox commented Nov 1, 2022

https://vaadin.com/docs/latest/components/grid/#inline-editing-java-only

Solution

XML

DataGrid

No specific setting to enable Inline Editor is required. The editorBuffered attribute is added to XML to define whether Inline Editor must be opened in buffered mode or not, e.g:

<dataGrid editorBuffered="false"/>

Columns

To make an editable column, the editable attribute is adde to XML:

...
<column key="name" editable="true"/>
...

This setting indicates that the default Editor Component (Column#setEditorComponent()) must be set for a column by loader.

editorActionsColumn

To utilize creation of a custom column with edit buttons that invoke default Editor methods such as editItem(), save(), cancel() and closeEditor() a brand new editorActionsColumn element is introduced.

<editorActionsColumn width="8em" flexGrow="0">
    <editButton text="Edit" icon="PENCIL"/>

    <saveButton icon="CHECK" themeNames="success"/>
    <cancelButton icon="CLOSE" themeNames="error"/> 

    <closeButton text="Close" icon="CLOSE"/> 
</editorActionsColumn>
  • editButton - starts editing of an item. Suitable for both buffered and non buffered mode.
  • saveButton - saves changes made in editor components. Suitable for buffered mode only.
  • cancelButton - discards changes made in editor components. Suitable for buffered mode.
  • closeButton - closes the edit mode. Suitable for non buffered mode only.

Each button support a limited set of attributes of standard button: text, icon, title, classNames, themeNames, iconAfterText.

editorActionsColumn is added relatively to other columns. In case of includeAll="true", editorActionsColumn is added at the end.

Java

DataGridEditor

To provide additional functionality, DataGrid returns instance of DataGridEditor which extends Vaadin Grid's Editor.

Please read JavaDoc :-)

Important note: to support platform mechanisms like data containers, value sources, etc. Column Editor Component MUST be added using DataGridEditor methods (DataGridEditor#setColumnEditorComponent()) instead of direct column API Column#setEditorComponent(). For example:

DataGridEditor<User> editor = usersTable.getEditor();

editor.setColumnEditorComponent("timeZoneId", generationContext -> {
    //noinspection unchecked
    JmixComboBox<String> timeZoneField = uiComponents.create(JmixComboBox.class);
    timeZoneField.setItems(List.of(TimeZone.getAvailableIDs()));
    timeZoneField.setValueSource(generationContext.getValueSourceProvider().getValueSource("timeZoneId"));
    timeZoneField.setWidthFull();
    timeZoneField.setClearButtonVisible(true);
    timeZoneField.setRequired(true);
    //noinspection unchecked,rawtypes
    timeZoneField.setStatusHandler(((Consumer) generationContext.getStatusHandler()));

    return timeZoneField;
});

Accompanying Changes

BufferedContainerValueSource

To support Inline Editor buffered mode the new ValueSource implementation is created: BufferedContainerValueSource. It implements methods from BufferedDataUnit:

  • write()
  • discard()
  • isBuffered()
  • isModified()

SupportsStatusHandler

By default, field components (e.g. TextField, ComboBox, etc.) display error messages in a label above them. Such behaviour has disadvantages in case of limited area of edit cell. To be able to define different way of displaying error messages a new SupportsStatusHandler interface is created. Components that implement this interface support error handling delegation.

By default, Inline Editor uses this handler to set error message of a component as its title, e.g. tooltip.

@glebfox glebfox changed the title [DatGrid] Support inline editing [DataGrid] Support inline editing Nov 11, 2022
@glebfox glebfox added this to Backlog in Release 1.5 via automation Nov 11, 2022
@glebfox glebfox moved this from Backlog to In progress in Release 1.5 Nov 11, 2022
@glebfox glebfox self-assigned this Nov 15, 2022
@glebfox glebfox moved this from In progress to Review in Release 1.5 Nov 24, 2022
glebfox added a commit that referenced this issue Dec 26, 2022
@glebfox glebfox moved this from Review to QA in Release 1.5 Dec 26, 2022
glebfox added a commit that referenced this issue Feb 16, 2023
Release 1.5 automation moved this from QA to Done Feb 21, 2023
@gorbunkov gorbunkov added this to the 1.5.0 milestone Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Release 1.5
  
Done
Development

No branches or pull requests

3 participants