summaryrefslogtreecommitdiffstats
path: root/documentation
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-06-27 15:42:01 +0300
committerHenri Sara <henri.sara@gmail.com>2017-06-27 15:42:01 +0300
commite4e2328a3a78d652cd09ef8293f233d31d899415 (patch)
tree26d0b17179952e662ab8559269154715ba10c265 /documentation
parent65ac37ae63f65d17731dafdab85f0be53158ae78 (diff)
downloadvaadin-framework-e4e2328a3a78d652cd09ef8293f233d31d899415.tar.gz
vaadin-framework-e4e2328a3a78d652cd09ef8293f233d31d899415.zip
Add presentation value providers for Grid (#9553)
This patch changes Grid Columns, so they can have different value and presentation types. A presentation provider can be given when setting the renderer for a column. This provider takes the value of the column on a row and chooses what to present for this value. Using this approach it is easier to have an editor for the actual backing data instead of the presentation of it. Fixes #8656 Resolves #9588
Diffstat (limited to 'documentation')
-rw-r--r--documentation/components/components-grid.asciidoc29
1 files changed, 29 insertions, 0 deletions
diff --git a/documentation/components/components-grid.asciidoc b/documentation/components/components-grid.asciidoc
index 5a9cef230b..6d73da72df 100644
--- a/documentation/components/components-grid.asciidoc
+++ b/documentation/components/components-grid.asciidoc
@@ -613,6 +613,7 @@ grid.addColumn(person -> {
}, new ComponentRenderer());
----
+
[[components.grid.renderer.custom]]
=== Custom Renderers
@@ -896,6 +897,34 @@ You can modify the error message by implementing a custom
[interfacename]#EditorErrorGenerator# with for the [classname]#Editor#.
+[[components.grid.presentation.provider]]
+=== Presentation Value Providers
+
+By default, a renderer displays the column value. If you want to edit an
+internal value (such as an address object) but show a simpler representation
+when not editing a row, a presentation value provider can be used.
+
+A presentation value provider converts the value of a cell (obtained with a
+value provider, and used by the editor) to a different representation to be
+shown by renderers when the cell is not being edited. A custom renderer can
+optionally be used for the presentation values.
+
+In the following example, we demonstrate one way to use a simplified
+presentation of an address column while allowing editing the full address:
+
+[source, java]
+----
+Column<Person, Address> column = grid.addColumn(Person::getAddress);
+// alternatively, the presentation provider can be given as an extra parameter
+// to addColumn()
+column.setRenderer(
+ address -> address.getCity() + " " + address.getCountry(),
+ new TextRenderer());
+column.setCaption("Address");
+column.setEditorComponent(new AddressField(), Person::setAddress);
+----
+
+
////
// Not supported in 8
[[components.grid.scrolling]]