Search code examples
extjsextjs4store

How to get values from Extjs getUpdatedRecords()?


When I try to retrieve just grid.getStore().getUpdatedRecords(), it works just fine, but when trying to enter that object and retrieve data from(data), I get is undefined

plugins: [
    Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToMoveEditor: 1,
        listeners: {
            'edit': function () {

                    var grid = Ext.getCmp('dataGrid');
                    var editedRecords = grid.getStore().getUpdatedRecords(); // <---- OK
                  //var editedFirstName = editedRecords.data.FirstName;
                  //console.log(editedFirstName);
                    console.log(editedRecords);
                }

         }
    })
]


Here is my Firebug showing that this object has data.FirstName, data.LastName, data.id


enter image description here


Solution

  • getUpdatedRecords returns an array of modified records. So you're code should be ...

    var grid = Ext.getCmp('dataGrid');
    var editedRecords = grid.getStore().getUpdatedRecords(); // <---- OK
    var editedFirstName = editedRecords[0].data.FirstName;
    

    Considering that you are commiting the updated record after each edit, otherwise the method will return also other previous modified records.

    Also there is an easier way to do this, and also more practical. The row editing event click takes two parameters the editor and the object e which contains:

    grid - The grid this editor is on
    view - The grid view
    store - The grid store
    record - The record being edited
    row - The grid table row
    column - The grid Column defining the column that initiated the edit
    rowIdx - The row index that is being edited
    colIdx - The column index that initiated the edit
    

    So you're code should be

    'edit': function (editor,e) {
         var grid = e.grid;
         var record = e.record;
         console.log(record.data.FirstName);
    }