1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    7
    Vote Rating
    0
    AdamSas is on a distinguished road

      0  

    Default 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

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You could listen to the BeforeStartEditEvent and remove/add the editor for the specific columns depending on your input.

  3. #3
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Quote Originally Posted by sven View Post
    You could listen to the BeforeStartEditEvent and remove/add the editor for the specific columns depending on your input.
    Sorry this was for Ext GWT 3.

    For Ext GWT 2 you need to listen to the BeforeEdit and remove/add the editor from the ColumnConfig

  4. #4
    Sencha User
    Join Date
    Nov 2011
    Posts
    7
    Vote Rating
    0
    AdamSas is on a distinguished road

      0  

    Default


    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:

    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(0codeTextFieldCellEditor);
                    } else {
                        
    grid.getColumnModel().setEditor(0codeLabelFieldCellEditor);
                    }
            }
    }); 
    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).

    Is it OK how I try to replace CellEditor in ColumnConfig?

    Thanks

  5. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    7
    Vote Rating
    0
    AdamSas is on a distinguished road

      0  

    Default


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

Thread Participants: 1

Tags for this Thread