Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Question about listgridfield and formatting

    Hello,

    I have lots of listgridfields with different formatting needs. I have therefor implemented lots of custom cellformatters, for example like this:

    Code:
    public class ReportFloatFormatter implements CellFormatter {
    
        @Override
        public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null) return null;
            try {
                Float flt = Float.parseFloat("" + value);
                return CommonConstants.defaultNumberFormat.format(flt);//this is '########0.##';
            } catch (Exception e) {
                return value.toString();
            }
        }
    }
    However, this means that when i have a databound listgrid for example, i still have to fetch out the individual fields and manually set the formatter in code for every place i want this custom format, like this:
    Code:
    ListGridField hoursField = grid.getField(NubaCommonConstants.[I]FIELD_HOURSFRACTION[/I]);
    hoursField.setCellFormatter(floatFormatter);
    This is a lot of code, and kind of counterintuitive since i define the fields in my datasource xml. It would be great if a listgrid somehow would know the formatting from the datasource xml definition.

    So, my question:

    Is there some better way to do this? I looked around at datasourcefield and found "setFormat", but i haven't been able to figure out if that could be used here somehow. Pointers would be much appreciated.
Working...
X