PDA

View Full Version : [FIXED] when call grid.reconfigure the aggregation row DONT reconfigure - rc1



fother
25 Jun 2009, 9:29 AM
code example.. click in the button



public class Gxt implements EntryPoint {

public class Data extends BaseModel {

public Data(String name, Double value) {
setName(name);
setValue(value);
}

public Data(String name, Double value, Double number) {
setName(name);
setValue(value);
setNumber(number);
}

public String getName() {
return get("name");
}

public Double getNumber() {
return get("number");
}

public Double getValue() {
return get("value");
}

public void setName(String name) {
set("name", name);
}

public void setNumber(Double number) {
set("number", number);
}

public void setValue(Double value) {
set("value", value);
}

}

public void onModuleLoad() {

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

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

column = new ColumnConfig();
column.setId("value");
column.setHeader("Value");
column.setAlignment(HorizontalAlignment.RIGHT);
column.setWidth(100);
configs.add(column);

final ListStore<Data> store = new ListStore<Data>();
store.add(new Data("name 1", 5.0));
store.add(new Data("name 2", 6.0));
store.add(new Data("name 3", 7.0));
store.add(new Data("name 4", 8.0));
store.add(new Data("name 5", 9.0));

ColumnModel cm = new ColumnModel(configs);

AggregationRowConfig<Data> averages = new AggregationRowConfig<Data>();
averages.setSummaryType("value", SummaryType.AVG);
averages.setRenderer("value", new AggregationRenderer<Data>() {

public Object render(Number value, int colIndex, Grid<Data> grid, ListStore<Data> store) {

if (value != null) {
return NumberFormat.getCurrencyFormat().format(value.doubleValue());
} else {
return "nothing";
}
}
});

cm.addAggregationRow(averages);

final Grid<Data> grid = new Grid<Data>(store, cm);
grid.setBorders(false);
grid.setAutoExpandColumn("name");
grid.setBorders(true);
grid.setSize(400, 200);

Button button = new Button("reconfigure grid", new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {

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

ColumnConfig newColumn = new ColumnConfig();
newColumn.setId("name");
newColumn.setHeader("Name");
newColumn.setWidth(200);
newConfigs.add(newColumn);

newColumn = new ColumnConfig();
newColumn.setId("value");
newColumn.setHeader("Value");
newColumn.setAlignment(HorizontalAlignment.RIGHT);
newColumn.setWidth(100);
newConfigs.add(newColumn);

newColumn = new ColumnConfig();
newColumn.setId("number");
newColumn.setHeader("Number");
newColumn.setAlignment(HorizontalAlignment.RIGHT);
newColumn.setWidth(100);
newConfigs.add(newColumn);

ColumnModel newCm = new ColumnModel(newConfigs);

AggregationRowConfig<Data> newAverages = new AggregationRowConfig<Data>();
newAverages.setSummaryType("value", SummaryType.AVG);
newAverages.setRenderer("value", new AggregationRenderer<Data>() {

public Object render(Number value, int colIndex, Grid<Data> grid, ListStore<Data> store) {

if (value != null) {
return NumberFormat.getCurrencyFormat().format(value.doubleValue());
} else {
return "nothing";
}
}
});

newAverages.setSummaryType("number", SummaryType.AVG);
newAverages.setRenderer("number", new AggregationRenderer<Data>() {

public Object render(Number value, int colIndex, Grid<Data> grid, ListStore<Data> store) {

if (value != null) {
return NumberFormat.getCurrencyFormat().format(value.doubleValue());
} else {
return "nothing";
}
}
});

newCm.addAggregationRow(newAverages);

final ListStore<Data> newStore = new ListStore<Data>();
newStore.add(new Data("name 1", 5.0, 8.0));
newStore.add(new Data("name 2", 6.0, 9.0));
newStore.add(new Data("name 3", 7.0, 10.0));
newStore.add(new Data("name 4", 8.0, 11.0));
newStore.add(new Data("name 5", 9.0, 12.0));

grid.reconfigure(newStore, newCm);

}

});

RootPanel.get().add(grid);
RootPanel.get().add(button);

}
}

darrellmeyer
25 Jun 2009, 1:28 PM
Fixed in SVN.

fother
25 Jun 2009, 3:47 PM
thanks :D

sthamman
11 Aug 2009, 5:17 PM
Thanks for all your efforts. GXT rocks! :)

GXT 2.0.1
Hosted Mode

The aggregation column on the table footer doesn't get hidden when setting the related columnconfig to hidden.

Also, the aggregation row doesn't align with the actual table rows anymore after reconfiguration, please see the attached screen shot.



public class AggregationGridExample implements EntryPoint {
public void onModuleLoad() {
Viewport root = new Viewport();
root.setLayout(new FitLayout());


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(400);
configs.add(column);

column = new ColumnConfig();
column.setId("symbol");
column.setHeader("Symbol");
column.setWidth(200);
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());

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
if (value == null)
return "";
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) {
if (value == null)
return "";
return number.format(value.doubleValue());
}
});
cm.addAggregationRow(averages);

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);

root.add(cp);
cp.addButton(new Button("Hide", new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent be) {
store.removeAll();
ColumnModel cm = grid.getColumnModel();
ColumnConfig cc = cm.getColumnById("last");
cc.setHidden(true);
store.add(TestData.getStocks());
grid.reconfigure(store, cm);
}
}));
RootPanel.get().add(root);
}
}

sven
12 Aug 2009, 12:44 AM
Already fixed in SVN

sthamman
13 Aug 2009, 11:04 PM
Thanks.

sthamman
19 Aug 2009, 12:20 PM
I'm still having this issue even with the svn code. Please check the above code & screenshot.

Thanks,
Sreenivas

kdragon
21 Aug 2009, 7:32 AM
this is an issue for me too (that the summary line scrolling gets out of sync with the table after refreshing data in the store, and other things)

would this be easy for me to patch the current release? also, i am concerned that the last poster said that he still has a problem after applying the fix.

is the next release about to come out?

any other work arounds available? i tried using grouping summaries and group everything together, but we are using the checkbox selection model, and that seems incompatible with aggregationrows.

Thanks
Keith

darrellmeyer
29 Sep 2009, 7:33 AM
We can't reproduce this. I have tested the code that was posted in this thread. If you are still seeing this problem please post sample code.