对于GridPanel里面的日期数据列:
RecordDef里面定义为:
- RecordDef recordDef = new RecordDef(
- new FieldDef[]{
- new StringFieldDef("company"),
- new FloatFieldDef("price"),
- new DateFieldDef("dates")//日期类型
- }
- );
ColumnConfig[]定义:
- ColumnConfig[] columns = new ColumnConfig[]{
- //column ID is company which is later used in setAutoExpandColumn
- new ColumnConfig("Company", "company", 160, true, null, "company"),
- new ColumnConfig("Price", "price", 35),
- new ColumnConfig("Last Date", "dates", 65,true,new DateRenderer("yyyy-MM-dd")),
- };
DateRenderer类的定义如下:
- public class DateRenderer implements Renderer {
- private DateTimeFormat dateTimeFormat;
- public DateRenderer(String format) {
- this.dateTimeFormat = DateTimeFormat.getFormat(format);
- }
- // public DateRenderer() {
- // this.dateTimeFormat = DateTimeFormat.getFormat("dd.MM.yyyy");
- // }
- public String render(Object value, CellMetadata cellMetadata,
- Record record, int rowIndex, int colNum, Store store) {
- return value != null ? dateTimeFormat.format((Date) value) : "";
- }
- }