How do I get the column type of a Vaadin 8 grid?

I am using Vaadin 8 to present table data with dynamic bean. so I have to define a boolean filter on the column.

For this I need a datatype column from a grid or column object. Is there a way to get the data types of a column?

In Vaadin 7 I can use container.getType (columnName)

+3


source to share


2 answers


In the Vaadin 8 data binding model, the property type is not explicitly known to the UI component (in your case Grid

). This information should come from your domain model.

If you find it difficult to get from your domain model, you can do:



// instead of new Grid(beanType)
PropertySet<YourBeanType> ps = BeanPropertySet.get(beanType);
Grid g = new Grid(ps);
...
// get the property type
// okay, this is ugly, but you get the idea
Class<?> type = ps.getProperty(yourPropertyName).get().getType();

      

+2


source


You can get the column type when setting styleGenerator

for a column. For example, I do the following to set a specific style if a column BigDecimal

:

Grid.Column c = grid.getColumn("id");
c.setStyleGenerator(obj -> {
       Object value = c.getValueProvider().apply(obj);
       if (value instanceof BigDecimal) {
           return "align-right";
       } 
       return null;
 });

      



I'm not sure if there is a way to get "outside" the style generator.

0


source







All Articles