Hello,
I have lots of listgridfields with different formatting needs. I have therefor implemented lots of custom cellformatters, for example like this:
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:
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.
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(); } } }
Code:
ListGridField hoursField = grid.getField(NubaCommonConstants.[I]FIELD_HOURSFRACTION[/I]); hoursField.setCellFormatter(floatFormatter);
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.