Information on properties have been edited in DataGrid.EditorPostCommitEvent

Hello,
I am trying to implement updating or related fields in awesome DataGrid component using DataGrid events, but none of them provides a way to figure out what a particular property is updated or not.

Using a value change listener for generated editable column component can’t seed to work - the value is overriden by the component later on.

Thanks in advance.

Regards,
Ilia.

Hi,

Take a look at this sample project data-grid-change-editor-fields-values-during-editing. It demonstrates how to implement what you want, for instance:

dataGrid.addEditorOpenListener(event -> {
	Map<String, Field> fieldMap = event.getFields();
	Field productField = fieldMap.get("product");
	Field productNameField = fieldMap.get("product.name");
	Field quantityField = fieldMap.get("quantity");
	Field totalField = fieldMap.get("total");

	ValueChangeListener listener = e -> {
		Product product = productField.getValue();
		Integer quantity = quantityField.getValue();
		if (product != null && product.getPrice() != null && quantity != null) {
			totalField.setValue(product.getPrice().multiply(BigDecimal.valueOf(quantity)));
		}

		productNameField.setValue(product != null ? product.getName() : null);
	};

	productField.addValueChangeListener(listener);
	quantityField.addValueChangeListener(listener);
});

Hello, Gleb,
thank you a lot, this is exactly what I was looking for.

1 Like