简体   繁体   English

SmartGWT:是否可以为列表网格中的某一行着色?

[英]SmartGWT: is it possible to color a a certain row in a list grid?

all is it possible to color a certain Row in smartGWT listGrid ? 所有可以在smartGWT listGrid中为某一行着色? i want to color just 1 row , not all the listGrid 我想只为1行着色,而不是所有listGrid

In SmartGWT, methods that end with Style (eg- get Style, getBaseStyle, getCellStyle, etc.) need to return a CSS class defined elsewhere (.css file, inline css in application load jsp, etc.). 在SmartGWT中,以Style结尾的方法( 例如,获取Style,getBaseStyle,getCellStyle等)需要返回在别处定义的CSS类(.css文件,应用程序加载jsp中的内联css等)。
Same applies for set Style methods. 同样适用于设置样式方法。

Unless lot of CSS customizations are done warranting the need for such, using getCellCSSText would probably be the best option. 除非完成大量的CSS自定义以保证需要, 否则使用getCellCSSText可能是最佳选择。

getCellCSSText returns CSS text per cell, and will be called during every redraw. getCellCSSText返回每个单元格的CSS文本,并将在每次重绘期间调用。

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;
    }
};

Its not required to extend ListGridRecord as indicated in showcase sample linked above, unless there are other reasons to do so. 它不需要扩展ListGridRecord,如上面链接的展示示例中所示,除非有其他原因这样做。

Never used SmartGWT, but looking at the JavaDoc, I'd say: 从来没有使用过SmartGWT,但是看看JavaDoc,我会说:

listGrid.getRecord(recordNum)

Also checkout this sample , that overrides the getBaseStyle() of the ListGrid . 也检出这 ,它覆盖getBaseStyle()的的ListGrid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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