From e4e2328a3a78d652cd09ef8293f233d31d899415 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 27 Jun 2017 15:42:01 +0300 Subject: 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 --- documentation/components/components-grid.asciidoc | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'documentation') 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 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]] -- cgit v1.2.3