Annotation Interface GridColumn
Grid.Column
to be auto-generated by a GridColumnScanner
.
This annotation annotates methods in a model class T
that backs a Grid<T>
. When the
class is scanned by a GridColumnScanner
, each annotation results in a corresponding Grid.Column
being added to the Grid
under construction, configured according to the various annotation properties.
The annotated method is often a bean property getter method, but this is not required.
Rendering
By default, the method's return value is used to render the column by simple conversion to a String
.
Custom rendering is possible by specifying a renderer()
, or by having the method return a Component
directly; see renderer()
for details;
Some examples:
// Container backing object class
public class User {
// Default rendering using String value
@GridColumn(header = "Username", width = "50px")
public String getUsername() { ... }
// Custom rendering based on property value using MyDobRenderer
@GridColumn(header = "DOB", sortable = true, renderer = MyDobRenderer.class)
public LocalDate getDateOfBirth() { ... }
// Custom rendering based on the entire backing object
@GridColumn(header = "✔︎", renderer = SelectedRenderer.class)
public void selectedColumn() { ... }
// Method directly returns a Component to be displayed
@GridColumn(header = "Status")
public Image statusColumn() { ... }
}
// Build Grid with auto-generated columns
final Grid<User> grid = new GridColumnScanner<>(User.class).buildGrid();
...
Some details regarding @GridColumn
annotations:
- Annotated methods must be instance methods taking zero parameters; annotations on other methods are ignored.
- Protected, package private, and private methods are supported (assuming they are accessible).
@GridColumn
annotations declared in super-types (including interfaces) are supported- If a method and the superclass or superinterface method it overrides are both annotated with
@GridColumn
, then the overridding method's annotation takes precedence (all properties are overridden). - If two methods with different names are annotated with
@GridColumn
for the same column key, then the declaration in the class which is a sub-type of the other wins (if the two classes are equal or not comparable, an exception is thrown). This allows subclasses to "override" which method supplies a given property. - If the method returns a sub-type of
Component
, then by default aSelfRenderer
is assumed. This lets you define a method that directly returns theComponent
to display. - If the annotated methods return
void
orVoid
, then arenderer()
is required and it must have a default constructor. - Columns will be ordered first by
order()
, then by property name.
- See Also:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionboolean
Get the auto width setting.Class<? extends SerializableFunction>
Get the CSS class name generator class.Get the name of this column's column group.Class<? extends Comparator>
Get theComparator
class to use for in-memory sorting.Class<? extends SerializableFunction>
Get the editor component generator class.int
Get the flex grow ratio.Get the column footer.boolean
Get the frozen setting.Get the column header.boolean
Get whether this column is the hierarchy column for aTreeGrid
.Get the column debug ID.Get the column key.double
Get the ordering value for this column.Get the custom renderer class to use.boolean
Get the user-resizable setting.boolean
Get the sortable setting.Class<? extends SortOrderProvider>
Get theSortOrderProvider
class.String[]
Get the back-end sort properties.String[]
Specify CSS properties to be set on the column viaStyle.set()
.Get the text alignment setting.Class<? extends SerializableFunction>
Get the tool tip generator class.Class<? extends ValueProvider>
Get theValueProvider
class to use to produce values used for in-memory sorting.boolean
Get whether to include this column as one of the columns with configurable visibility by way ofGridColumnScanner.addVisbilityMenuItems()
.boolean
Get initial visibility setting.Get the width.
-
Element Details
-
renderer
Get the custom renderer class to use.If this property is not specified,
Grid.addColumn(ValueProvider)
is used to create the column; if this property is specified,Grid.addColumn(Renderer)
is used to create the column using an instance of the specified renderer type.As a special case, when the annotated method returns a sub-type of
Component
and this property is not specified otherwise, then aSelfRenderer
is used.If the annotated method returns
void
orVoid
, then this property must specify a custom renderer type having a default constructor.Otherwise, the custom renderer type can have either a default constructor or a constructor taking a
ValueProvider
. In the former case, the renderer accepts the model object backing the entire row, not the return value from the method. In the latter case, the givenValueProvider
provides access to the method's return value (by invoking the method on demand).- Returns:
- column renderer class
- See Also:
- Default:
- com.vaadin.flow.data.renderer.Renderer.class
-
autoWidth
boolean autoWidthGet the auto width setting.- Returns:
- auto width
- See Also:
- Default:
- false
-
classNameGenerator
Class<? extends SerializableFunction> classNameGeneratorGet the CSS class name generator class.- Returns:
- column comparator
- See Also:
- Default:
- com.vaadin.flow.function.SerializableFunction.class
-
columnGroup
String columnGroupGet the name of this column's column group.Columns with the same (non-empty) group name will be grouped together under a common super-heading for the group.
- Returns:
- column group name, or empty string for none
- See Also:
- Default:
- ""
-
comparator
Class<? extends Comparator> comparatorGet theComparator
class to use for in-memory sorting.If this property is set,
sortable()
should also be true, andvalueProviderComparator()
should not be set.- Returns:
- column comparator
- See Also:
- Default:
- java.util.Comparator.class
-
valueProviderComparator
Class<? extends ValueProvider> valueProviderComparatorGet theValueProvider
class to use to produce values used for in-memory sorting.If this property is set,
sortable()
should also be true, andcomparator()
should not be set.- Returns:
- column comparator
- See Also:
- Default:
- com.vaadin.flow.function.ValueProvider.class
-
editorComponent
Class<? extends SerializableFunction> editorComponentGet the editor component generator class.- Returns:
- editor component class
- See Also:
- Default:
- com.vaadin.flow.function.SerializableFunction.class
-
flexGrow
int flexGrowGet the flex grow ratio.- Returns:
- column flex grow ratio.
- See Also:
- Default:
- 1
-
frozen
boolean frozenGet the frozen setting.- Returns:
- column frozen setting
- See Also:
- Default:
- false
-
header
String headerGet the column header.- Returns:
- column header
- See Also:
- Default:
- ""
-
hierarchyColumn
boolean hierarchyColumnGet whether this column is the hierarchy column for aTreeGrid
.If this property is set, and the
Grid
being configured is aTreeGrid
, then the column is created as an expand/collapse "hierarchy column".How the column is created depends on
renderer()
. If arenderer()
class is specified, then it must subclassComponentRenderer
, andTreeGrid.addComponentHierarchyColumn()
will be used to create the column using the rendered components. Otherwise,TreeGrid.addHierarchyColumn()
is used to create the column, usingString.valueOf()
applied to the annotated method's return value.If the
Grid
being configured is not aTreeGrid
, this column is ignored.- Returns:
- column debug ID
- See Also:
- Default:
- false
-
id
String idGet the column debug ID.- Returns:
- column debug ID
- See Also:
- Default:
- ""
-
key
String keyGet the column key.If this is left unset, the annotated method's bean property name method is used.
- Returns:
- column key
- See Also:
- Default:
- ""
-
resizable
boolean resizableGet the user-resizable setting.- Returns:
- column resizable setting
- See Also:
- Default:
- false
-
sortable
boolean sortableGet the sortable setting.- Returns:
- column sortable setting
- See Also:
- Default:
- false
-
sortOrderProvider
Class<? extends SortOrderProvider> sortOrderProviderGet theSortOrderProvider
class.If this property is set,
sortable()
should also be true.- Returns:
- column
SortOrderProvider
- See Also:
- Default:
- com.vaadin.flow.component.grid.SortOrderProvider.class
-
sortProperties
String[] sortPropertiesGet the back-end sort properties.If this property is set,
sortable()
should also be true.- Returns:
- sort properties
- See Also:
- Default:
- {}
-
styleProperties
String[] stylePropertiesSpecify CSS properties to be set on the column viaStyle.set()
.The array value consists of name, value pairs. If the array has odd length, the last element is ignored.
- Returns:
- zero or more style property name, value pairs
- See Also:
- Default:
- {}
-
textAlign
ColumnTextAlign textAlignGet the text alignment setting.- Returns:
- column text alignment setting
- See Also:
- Default:
- START
-
tooltipGenerator
Class<? extends SerializableFunction> tooltipGeneratorGet the tool tip generator class.- Returns:
- tool tip generator class
- See Also:
- Default:
- com.vaadin.flow.function.SerializableFunction.class
-
visible
boolean visibleGet initial visibility setting.- Returns:
- whether column is visible
- See Also:
- Default:
- true
-
visibilityMenu
boolean visibilityMenuGet whether to include this column as one of the columns with configurable visibility by way ofGridColumnScanner.addVisbilityMenuItems()
.The menu item labels are taken from the
header()
, if any, otherwisekey()
.- Returns:
- whether column has configurable visibility
- See Also:
- Default:
- false
-
width
String widthGet the width.- Returns:
- column width
- See Also:
- Default:
- ""
-
order
double orderGet the ordering value for this column.- Returns:
- column order value
- Default:
- 0.0
-