PDA

View Full Version : grid + Aggregation Row + reconfigure



fother
27 Jul 2009, 1:25 PM
how to reproduce..
1 - click in hide button
2 - click in show button

you can try call the methods {layout, layout(true), repaint}.. the aggregation rows.. never more are displayed..

in this example I use the same store and column model (you can create a new store and column model and the result its the same)

tested on win vista
2.0.1

code example


public void onModuleLoad() {

final NumberFormat currency = NumberFormat.getCurrencyFormat();
final NumberFormat number = NumberFormat.getFormat("0.00");
final NumberCellRenderer<Grid<Stock>> numberRenderer = new NumberCellRenderer<Grid<Stock>>(currency);

GridCellRenderer<Stock> change = new GridCellRenderer<Stock>() {
public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<Stock> store,
Grid<Stock> grid) {
double val = (Double) model.get(property);
String style = val < 0 ? "red" : "green";
return "<span style='color:" + style + "'>" + number.format(val) + "</span>";
}
};

GridCellRenderer<Stock> gridNumber = new GridCellRenderer<Stock>() {
public String render(Stock model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<Stock> store,
Grid<Stock> grid) {
return numberRenderer.render(null, property, model.get(property));
}
};

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader("Company");
column.setWidth(200);
configs.add(column);

column = new ColumnConfig();
column.setId("symbol");
column.setHeader("Symbol");
column.setWidth(100);
configs.add(column);

column = new ColumnConfig();
column.setId("last");
column.setHeader("Last");
column.setAlignment(HorizontalAlignment.RIGHT);
column.setWidth(100);
column.setRenderer(gridNumber);
configs.add(column);

column = new ColumnConfig("change", "Change", 100);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setRenderer(change);
configs.add(column);

column = new ColumnConfig("date", "Last Updated", 100);
column.setAlignment(HorizontalAlignment.RIGHT);
column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
configs.add(column);

final ListStore<Stock> store = new ListStore<Stock>();
store.add(TestData.getStocks());

final ColumnModel cm = new ColumnModel(configs);

cm.addHeaderGroup(0, 2, new HeaderGroupConfig("Stock Performance", 1, 2));
cm.addHeaderGroup(0, 0, new HeaderGroupConfig("Stock Information", 1, 2));

AggregationRowConfig<Stock> averages = new AggregationRowConfig<Stock>();
averages.setHtml("name", "Average");

// with summary type and format
averages.setSummaryType("last", SummaryType.AVG);
averages.setSummaryFormat("last", NumberFormat.getCurrencyFormat());

// with renderer
averages.setSummaryType("change", SummaryType.AVG);
averages.setRenderer("change", new AggregationRenderer<Stock>() {
public Object render(Number value, int colIndex, Grid<Stock> grid, ListStore<Stock> store) {
// you can return html here
return number.format(value.doubleValue());
}
});
cm.addAggregationRow(averages);

averages = new AggregationRowConfig<Stock>();
averages.setHtml("name", "Maximum");

averages.setSummaryType("last", SummaryType.MAX);
averages.setSummaryFormat("last", NumberFormat.getCurrencyFormat());

averages.setSummaryType("change", SummaryType.MAX);
averages.setRenderer("change", new AggregationRenderer<Stock>() {
public Object render(Number value, int colIndex, Grid<Stock> grid, ListStore<Stock> store) {
return number.format(value.doubleValue());
}
});
cm.addAggregationRow(averages);

final ContentPanel cp = new ContentPanel();
cp.setCollapsible(true);
cp.setAnimCollapse(false);
cp.setFrame(true);
cp.setHeading("Aggregation Rows");
cp.setButtonAlign(HorizontalAlignment.CENTER);
cp.setLayout(new FitLayout());
cp.setBounds(10, 10, 600, 350);

final Grid<Stock> grid = new Grid<Stock>(store, cm);
grid.setBorders(false);
grid.setAutoExpandColumn("name");
grid.setBorders(true);
cp.add(grid);

Button hide = new Button("hide", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
cp.hide();
}
});

Button show = new Button("show", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
grid.reconfigure(store, cm);
cp.show();
}
});

RootPanel.get().add(hide);
RootPanel.get().add(show);
RootPanel.get().add(cp);
}

sven
27 Jul 2009, 1:35 PM
This is a limitation in the browsers.

Two possibilties:

1) reconfigrue your grid after showing it
2) change the hidemode of your contentpanel to something different than HideMode.DISPLAY

fother
27 Jul 2009, 1:41 PM
thanks sven..

I try the first option.. that its more easy and solved.. (and resolved another issues) :)

Arno.Nyhm
29 Jul 2009, 3:33 AM
(and resolved another issues) :)

what are the other issues. pls describe it also, so someone with the same other issues find a solution :-)