Default table cell (property) alignment

Hi,

I would like to change the default property alignement in a table (which is LEFT)

In fact I would like to set this depending on the type of the property
Texts : to the left, numerics to the right, and center the rest…

Where to set this code ?

It tried to override the formatPropertyValue of the Table.class. But here, I can’t change the alignment.
What would be the best place to set this ?

Thanks

Hi!

There is an api for it:


        t.setColumnAlignment("propertyId",
                Table.ALIGN_RIGHT);

cheers,
matti

:wink:

I know this API… But I would like that my table do it for me…

I started to extends the vaadin Table, and I 'm searching where to set this alignment (using the API), so when I will set the containerDatasource, the table will automatically align each column/property depending on its type…

Just a quick thought:

You could possible extend Table and override

public String getColumnAlignment(Object propertyId) {
        final String a = columnAlignments.get(propertyId);
        return a == null ? ALIGN_LEFT : a;
    }

And return another default than ALIGN_LEFT or check something from the data source e.g. using getContainerDataSource().getType(propertyId)

That’s IT !

Thanks you very much


@Override
				public String getColumnAlignment(Object propertyId) {
					Class<?> t = getContainerDataSource().getType(propertyId);
					if (t == Double.class)
						return Table.ALIGN_RIGHT;
					if (t == Date.class)
						return Table.ALIGN_CENTER;
					return super.getColumnAlignment(propertyId);
				}