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

后端 未结 2 694
野趣味
野趣味 2021-01-20 01:49

all is it possible to color a certain Row in smartGWT listGrid ? i want to color just 1 row , not all the listGrid

相关标签:
2条回答
  • 2021-01-20 02:35

    In SmartGWT, methods that end with Style (e.g.- getStyle, getBaseStyle, getCellStyle, etc.) need to return a CSS class defined elsewhere (.css file, inline css in application load jsp, etc.).
    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.

    getCellCSSText returns CSS text per cell, and will be called during every 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;
        }
    };
    

    Its not required to extend ListGridRecord as indicated in showcase sample linked above, unless there are other reasons to do so.

    0 讨论(0)
  • 2021-01-20 02:41

    Never used SmartGWT, but looking at the JavaDoc, I'd say:

    listGrid.getRecord(recordNum)

    • setCustomStyle(String customStyle)
    • setAttribute(String property, BaseClass value)

    Also checkout this sample, that overrides the getBaseStyle() of the ListGrid.

    0 讨论(0)
提交回复
热议问题