Search code examples
javascriptextjsextjs-grid

Extjs : Change grid cell value on every change of another cell in the same row


I am working on extjs Grid panel which has 2 columns as shown in the below fig.

enter image description here

My requirement is to change "Short Name" cell value on every change of corresponding "Task Description" cell value. I have used editor for "Task Description" column as shown below.

columns: [
    { 
        text: 'Task Description',  
        dataIndex: 'TaskDescription', 
        flex : 1.5, 
        editor: {
            xtype : 'textarea', 
            allowBlank : false,
            listeners : {
                change : function(field, e) {
                    var text = field.value;
                    if(text.length <= 26 && !text.match(/[.:-]/)) {
                        if(text.length == 26) {
                            text = text[25]==' ' ? text : text.substring(0, text.lastIndexOf(' '));
                        } 
                        //code to set short name cell value.
                    }
                }
            }
        } 
    },
    { 
        text: 'Short Name', 
        dataIndex: 'Name', 
        width: 130
    }
]

But how can i access "Short Name" column to set it from change event function.

Please suggest me the solution.

Thanks in advance.


Solution

  • I got solution to this problem.

    listeners : {
        change : function(field, newValue,o ,e) {
            var text = field.value;
            if(text.length <= 26 && !text.match(/[.:-]/)) {
                if(text.length == 26) {
                    text = text[25]==' ' ? text : text.substring(0, text.lastIndexOf(' '));
                } 
                var selectedModel = this.up('grid').getSelectionModel().getSelection()[0];
                selectedModel.set('Name', text);
            }
        }
    }