2

I use smartgwt 2.4.

I'm trying to style a ListGridRecord. I want to get the Canvas component of it, but I cannot find a reference anywhere.

I know there are methods in ListGrid as createRecordComponent or getBackgroundComponent etc., but these don't return any component. They are meant as an override point (user can define his/her own components instead of default). But this is not what I want. I want to get the default component and change it (style it).

I know there's a setCellFormatter method at the ListGrid, where I can set format of a cell, but it only regards the text component of a cell, not the whole row (record).

I know there's a getBaseStyle method, where I can put a class name, but this is still not what I want. I want to change the style dynamically (e.g. I want to put any background color to the component) not only put a static class(es) (where the background color is predefined).

Can anybody help? Thanks.

fireshadow52
  • 6,298
  • 2
  • 30
  • 46
xMichal
  • 624
  • 2
  • 7
  • 19

1 Answers1

0

I'm afraid your options are a little limited when it comes to SmartGWT. One, although not very simple way of achieving that is overriding the ListGrid.getCellCSSText(ListGridRecord record, int rowNum, int colNum) method on creation of ListGrid as shown here.
That is how I have created customized cell styles.

final ListGrid grid= new ListGrid() {
    protected String getCellCSSText(ListGridRecord record, int rowNum, int colNum) {
        if (getFieldName(colNum).equals("MyColumnName")) {
            ListGridRecord record = (ListGridRecord) record;
            if (record.getSomeValue() > 20) {
                return "font-weight:bold; color:red;";
            } else if (record.getSomethingElse() < 5) {
                return "font-weight:bold; color:blue;";
            } else {
                return super.getCellCSSText(record, rowNum, colNum);
            }
        } else {
            return super.getCellCSSText(record, rowNum, colNum);
        }
    }
};
Kimi
  • 6,239
  • 5
  • 32
  • 49