Editing cell values

NatTable supports the following editing features

  1. Inline cell editing via a text box, Combo box or a check box
  2. Multiple values can be edited simultaneously via a popup
  3. Editing updates the underlying list data structure

The EditableGridExample is the best place to look at. The default cell editing configuration is provided by the DefaultEditConfiguration

Making cells editable

Editing is turned off by default. To enable editing an IEditableRule has to be registered against the cell label. The isEditable
method must return true. This rule must be registered against the cell label as shown below

configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, "myCellLabel");

Cell editor

This is the widget which gets activated when a cell is put into edit mode. Text box, combo box and check box are provided out of the box. These widgets implement the ICellEditor interface. Note that there is only one instance of a cell editor active at any time. The editor must be registered against the cell label as follows

configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, comboBoxCellEditor, DisplayMode.EDIT, "myCellLabel");

Data validation

Data validation rules can be specified for the editable cells. Updates will be applied to the underlying list only if they pass the validation check. These are relevant in case of text boxes where the user can enter free text. These rules must implement the IDataValidator interface.

configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, getSecurtityIdValidator(), DisplayMode.EDIT, "myCellLabel");

How are cell values committed.

Data validation rules can be specified for the editable cells. Updates will be applied to the underlying list only if they pass the validation check. These are relevant in case of text boxes
where the user can enter free text. These rules must implement the IDataValidator interface.

configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, getSecurtityIdValidator(), DisplayMode.EDIT, "myCellLabel");

How are cell values committed.

A cell editor fires an UpdateDataCommand to commit the new value for a cell. This command is handled by the DataLayer via the UpdateDataCommandHandler. Ultimately the IDataProvider will update the underlying data structure.

Handling the data update differently

If you want to execute a custom action when the user edits a cell you will have to:

  1. Deregister the UpdateDataCommandHandler
  2. Register your custom command handler for handling the UpdateDataCommand

The code will look something like this

    bodyDataLayer.unregisterCommandHandler(UpdateDataCommand.class);
    bodyDataLayer.registerCommandHandler(new MyUpdateDataCommandHandler());