PDA

View Full Version : Update all rows into a EditorGrid



listirer
17 Feb 2012, 11:19 AM
I use an EditorGrid with a combo as column.


final SimpleComboBox<MyValue> comboBox = new SimpleComboBox<MyValue>();
comboBox.setEditable(false);
comboBox.setTriggerAction(ComboBox.TriggerAction.ALL);
comboBox.add(MyValue.getAll());
CellEditor comboEditor = new CellEditor(comboBox) {

@Override
public Object preProcessValue(Object value) {
if (value == null) {
return value;
}
return comboBox.findModel((MyValue) value);
}

@Override
public Object postProcessValue(Object value) {
if (value == null) {
return value;
}
return ((SimpleComboValue<MyValue>) value).getValue();
}
};
GridCellRenderer<MyObject> renderer = new GridCellRenderer<MyObject>() {

@Override
public Object render(MyObject model, String property,
ColumnData config, int rowIndex, int colIndex,
ListStore<MyObject> store,
Grid<MyObject> grid) {
MyValue value = model.getValue();
return "<span style='color:" + value.toString()
+ "'>" + value + "</span>";
}
};
ColumnConfig column = new ColumnConfig();
column.setId("value");
column.setHeader("Value");
column.setWidth(150);
column.setFixed(true);
column.setEditor(comboEditor);
column.setRenderer(renderer);


I would update a property for all objects into the store, and so view the change into my grid, ie into the combo for each rows.


store.setKeyProvider(new ModelKeyProvider<MyObject>() {

@Override
public String getKey(MyObject model) {
return model.getId();
}
});

...

for(String id : IDS){
store.findModel(id).setValue(DEFAULT_VALUE);
}


How do I?

listirer
27 Feb 2012, 10:09 AM
A workaround for that is:


for(String id : IDS){
store.findModel(id).setValue(DEFAULT_VALUE);
}
grid.getView().refresh(false);


But for all the cells of the column don't will be market with triangle in upper-left that indicate the changing.

Can I do it better...

listirer
27 Feb 2012, 5:21 PM
I discovered the Record object useful for my purpose.
This is the code:


for(String id : IDS){
MyObject obj = store.findModel(id);
Record r = store.getRecord(obj);
r.set("value",DEFAULT_VALUE);
}

A.Rothe
28 Feb 2012, 12:39 AM
I think you can simply call store.update(model) to generate an event, which refreshes the model representation within the grid.

~Andre

listirer
28 Feb 2012, 2:51 AM
With this previous post I fix it.