Search code examples
gxt

Best way to render Boolean column as Yes/No rather than true/false


I've got a ColumnConfig that I would like to render as a Yes/No rather than the default true/false.

I've tried converting the ColumnConfig from <M, Boolean> to <M, String> and the ValueProvider to return the Y/N String. This trips up the BooleanFilter.validateModel().

Is there a better way to keep the Boolean type but change the rendering?


Solution

  • Digging into the GXT source code, I noticed ColumnConfig has a Cell reference.

    Adding a call to setCell() with a modified AbstactCell<Boolean> does the trick.

    columnConfig.setCell( new AbstractCell<Boolean>() {
    
        @Override
        public void render(Context context, Boolean value,
            SafeHtmlBuilder sb) {
            if (value) {
                sb.append(SafeHtmlUtils.fromSafeConstant("Yes"));
            } else {
                sb.append(SafeHtmlUtils.fromSafeConstant("No"));
            }
        }
    });