Java – SmartGWT: can I color a row in the list grid?
•
Java
All can color a row in SmartGWT listGrid?
Solution
In SmartGWT, methods ending in style (such as GetStyle, getbasestyle, getcellstyle, etc.) need to return CSS classes defined elsewhere (. CSS file, inline CSS in application loading JSP, etc.)
Unless a lot of CSS customization is done to ensure the need, getcellcsstext may be the best choice
Getcellcsstext returns the CSS text of each cell and will be called during each redraw
final ListGrid resultsGrid = new ListGrid() { @Override protected String getCellCSSText(ListGridRecord record,int rowNum,int colNum) { String style = super.getCellCSSText(record,rowNum,colNum); // conditions can check values in record using rowNum,colNum as well as record attributes if (record.getAttribute("<grid-field-name>").equals(<value>)) { if (this.getFieldName(colNum).equals("<certain-grid-field-name>") && record.getAttribute("<grid-field-name>").equals(<specific-value>)) { style = "font-weight:bold"; // only that cell in that row becomes bold } else { style = "color:red"; // all other cells in that row become red } } else if (record.getAttribute("<other-grid-field-name>").equals(<value>)) { style = "color:green"; // entire row changed to green if one column in this row contain a specific value } return style; } };
It does not need to extend the listgridrecord, as shown in the example shown in the link above, unless there is another reason to do so
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码