これを行うには 2 つのオプションがあります。まず、データソースから既に変更された値を返すため、10737418240 の代わりに「10 GB」の文字列値を返す必要があります。
私には 2 番目のアプローチの方が適しているようです。SimpleType 機能を使用する必要があります。あなたのための例があります:
public class PopulationType extends SimpleType {
public PopulationType() {
super("population", FieldType.TEXT);
// format values in the grid
this.setSimpleTypeValueExtractor(new SimpleTypeValueExtractor() {
@Override
public Object getAtomicValue(Object value) {
if (value instanceof Integer && ((Integer) value) > 1000000) {
return ((Integer) value) / 1000000 + " Mln";
}
return "" + value;
}
});
}
}
public void onModuleLoad() {
final ListGrid countryGrid = new ListGrid();
countryGrid.setWidth100();
countryGrid.setHeight100();
countryGrid.setAutoFetchData(true);
countryGrid.setShowFilterEditor(true);
countryGrid.setShowAllRecords(true);
WorldXmlDS ds = WorldXmlDS.getInstance();
ds.getField("population").setType(new PopulationType());
countryGrid.setDataSource(ds);
countryGrid.draw();
}
SimpleType インスタンスをフォーマットするフィールドに設定し、SimpleTypeValueExtractor を設定して、表示、フィルタリング、並べ替えに使用される getAtomicValue をオーバーライドします。
オーバーライドできるメソッドは他にもあります。たとえば、グリッドの値を編集する必要がある場合は、SimpleTypeValueUpdater も設定する必要があります。