PDA

View Full Version : grid column widens with force fit



lukaszk
8 Feb 2010, 11:51 PM
I have a problem with grid which view has forceFit attribute set to true. Every time I reload it's store (store.removeAll() and then store.add(...)) I see that last column in grid widens.
GWT version: 2.0.1
GXT version: 2.1.0
Platform: Windows XP
Web browser: any

My code that demonstrates problem:



package gxttest.client;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.ui.RootPanel;

public class TestGXT implements EntryPoint {

Grid<ModelData> grid;
Button rebindButton;
List<ModelData> data;


private List<ModelData> createTestData() {
List<ModelData> res = new ArrayList<ModelData>(50);
for (int i = 0; i < 50; i++) {
ModelData item = new BaseModel();
item.set("a", Random.nextInt(1000));
item.set("b", Random.nextInt(1000));
res.add(item);
}
return res;
}


public void onModuleLoad() {
data = createTestData();

initGrid();

LayoutContainer lc = new LayoutContainer();
lc.add(grid);
lc.add(rebindButton = new Button("Rebind"));

RootPanel.get().add(lc);

rebindButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
bind();
}
});
}


private void initGrid() {
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("a", "A", 100));
columns.add(new ColumnConfig("b", "B", 150));
ColumnModel cm = new ColumnModel(columns);
grid = new Grid<ModelData>(new ListStore<ModelData>(), cm);
grid.getView().setForceFit(true);
grid.setHeight(300);
}


private void bind() {
grid.getStore().removeAll();
grid.getStore().add(data);
}

}