Hybrid View
-
16 Jan 2012 12:30 PM #1
RowEditor with a conditionally enabled cell
RowEditor with a conditionally enabled cell
Hi All,
I need a Grid with several columns and a RowEditor, where some columns are conditionally enabled for editing and sometimes not. It depends on the other values in that row. E.g. we have a grid with columns age and personalId. When a value in age > 18, personalId should be enabled for editing (TextField). Otherwise it should be disabled for editing.
How can I achieve such behaviour?
Regards
-
16 Jan 2012 12:33 PM #2
You could listen to the BeforeStartEditEvent and remove/add the editor for the specific columns depending on your input.
-
16 Jan 2012 12:47 PM #3
-
16 Jan 2012 2:11 PM #4
Thank you for your solution. BeforeEdit event works very well - it is invoked every time I start editing a row with RowEditor. Unfortunately changing editor for ColumnConfig is not working in my code. It seems that after the first assignment of CellEditor the editor is not changed in subsequent calls of RowEditor.
I changed my requirement so that age column should be editable only when it was empty before the start of editing, otherwise the previously set value should only be displayed. This should be achieved with the following code:
Unfortunately the "age" column is always editable even if I start editing for the second time (in that case column age is not empty because I put some value in the first editing).PHP Code:final CellEditor codeTextFieldCellEditor = new CellEditor(new TextField<String>());
final CellEditor codeLabelFieldCellEditor = new CellEditor(new LabelField());
rowEditor.addListener(Events.BeforeEdit, new Listener<RowEditorEvent>() {
@Override
public void handleEvent(RowEditorEvent be) {
ModelData modelData = grid.getStore().getAt(be.getRowIndex());
if(modelData == null || modelData.get("age") == null) {
grid.getColumnModel().setEditor(0, codeTextFieldCellEditor);
} else {
grid.getColumnModel().setEditor(0, codeLabelFieldCellEditor);
}
}
});
Is it OK how I try to replace CellEditor in ColumnConfig?
Thanks
-
18 Jan 2012 2:58 AM #5
For some reasons the solution with changing Editor on BeforeEdit event does not work, but the aforementioned requirement can be achieved in a different way - instead replacing Editor, a TextField attached to CellEditor can be disabled/enabled depending on custom condition.
PHP Code:final TextField editorField = new TextField<String>();
final CellEditor codeTextFieldCellEditor = new CellEditor(editorField);
rowEditor.addListener(Events.BeforeEdit, new Listener<RowEditorEvent>() {
@Override
public void handleEvent(RowEditorEvent be) {
ModelData modelData = grid.getStore().getAt(be.getRowIndex());
if(modelData == null || modelData.get("age") == null) {
editorField.enable();
} else {
editorField.disable();
}
}
});


Reply With Quote