PDA

View Full Version : dynamic columns in editorgrid



mattjcurry
9 Dec 2010, 2:07 PM
I have an editor grid with dynamic columns. The number of columns depends on the size of a certain list.

What I have found is that even if I call grid.reconfigure(store, columnmodel), that the new columns are not clickable.

My goal is to have an editor attached to them, but the editor does not appear to work. The only columns that are selectable are the ones that were in the original grid.


public void setColumns(List<ColumnConfig> newCols) {
this.cols = newCols;
for (int i=0; i < cols.size(); i++) {
cols.get(i).setColumnStyleName("tbl-head");
cols.get(i).setNumberFormat(NumberFormat.getFormat("0"));
//GWT.log("column : " + i);
}

ColumnModel model = new ColumnModel(cols);
GWT.log(model.getColumnCount() + "columns in model");
for(int i=1; i < cols.size(); i++) {
SpinnerField spinnerField = new SpinnerField();
spinnerField.setIncrement(1);
spinnerField.setMinValue(0);
spinnerField.getPropertyEditor().setType(Integer.class);
spinnerField.getPropertyEditor().setFormat(NumberFormat.getFormat("0"));
CellEditor spinEditor = new CellEditor(spinnerField);
cols.get(i).setEditor(spinEditor);
}
lbGrid.reconfigure(lbStore, model);
}

sven
9 Dec 2010, 2:13 PM
Can you please post a fully working testcase implementing EntryPoint that fully describes what you are doing?

mattjcurry
9 Dec 2010, 3:18 PM
I did a quick test and it totally works. I must be doing something weird. I am going to have to look a little harder at my code.

public class Editorgridtest implements EntryPoint {


public void onModuleLoad() {

ContentPanel p = new ContentPanel();
p.setHeading("test editor grid");
p.setWidth(-1);
p.setHeight(-1);

ArrayList cols = new ArrayList<ColumnConfig>();
ColumnConfig tcc = new ColumnConfig("title", "title", 50);
cols.add(tcc);
ColumnModel cm = new ColumnModel(cols);
final ListStore store = new ListStore();
ArrayList storeList = new ArrayList();
for(int i=0; i<4; i++) {
BaseModel bm = new BaseModel();
bm.set("title", "title" + i);
storeList.add(bm);
}
store.add(storeList);

final EditorGrid myGrid = new EditorGrid(store, cm);
myGrid.setAutoHeight(true);
p.add(myGrid);

Button myButton = new Button("get more columns");
p.add(myButton);
SelectionListener<ButtonEvent> listener =
new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
//from here we get a new store and new column config.

int colsToAdd = Random.nextInt(5)+2;
ArrayList newStore = new ArrayList();

ArrayList newCols = new ArrayList();

ColumnConfig title = new ColumnConfig("title", "title", 50);
newCols.add(title);
for(int j = 0; j < colsToAdd; j++) {
ColumnConfig tempCol = new ColumnConfig("col"+j, "col"+j, 50);
SpinnerField spinnerField = new SpinnerField();
spinnerField.setIncrement(1);
spinnerField.setMinValue(0);
spinnerField.getPropertyEditor().setType(Integer.class);
spinnerField.getPropertyEditor().setFormat(NumberFormat.getFormat("0"));
CellEditor spinEditor = new CellEditor(spinnerField);
tempCol.setEditor(spinEditor);
newCols.add(tempCol);
}

for(int i=0; i<store.getCount(); i++) {
BaseModel bm = new BaseModel();
bm.set("title", store.getAt(i).get("title"));

for(int j = 0; j < colsToAdd; j++) {
bm.set("col"+j, 0);

}
newStore.add(bm);
}
store.removeAll();
store.add(newStore);

myGrid.reconfigure(store,new ColumnModel(newCols));
}
};
myButton.addSelectionListener(listener);

RootPanel.get().add(p);
}

mattjcurry
9 Dec 2010, 3:57 PM
the issue was related to having a space in the column id.