简体   繁体   中英

How to get the applied backgroundcolor from a Row and a Cell of Vaadin TreeGrid/Grid?

Im using the Vaadin version 8.6.4 for Java and I have a dataset that is represented on a TreeGrid. Until now I could not get the styleName that is applied to any row or any cell. There is any method or trick to get the actual style of a cell/row in vaadin? The list of styles are added like the code that is below.

I though also setting an Id to all cells before the Grid get created by overrideing the intern method of Grid Class. After that i should be able to fired a Javascript function on the client-side for searching the style of a cell by its id. But all that has been so complicated, so I have not been successful.

final String reservationColor  = "background-color: "green" !important;";   
final String STYLENAME_RESERVED = "reserved";

Styles styles = Page.getCurrent().getStyles();
styles.add(".v-treegrid-cell." + STYLENAME_RESERVED +"{"+ reservationColor + "}");

TreeGrid is directly exteding Grid, so you should be able to use similar methods to style the TreeGrid.

The preferred way to eg change cell background color is to use style generator

There is already question about that here with answer: How to set cell background color in grid/table in view in Vaadin?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM