Search code examples
javascriptextjsextjs5sencha-architect

How to get "Column Name" and "Previous Value" from Cell Editing Grid


I have a grid for which Cell editing plugin has been activated.

Once I updated few of the columns, I press Save button and all of the updated records (Row) are sent back with following code:

var grid = Ext.ComponentQuery.query('#CheckGrid')[0];
var store = Ext.data.StoreManager.lookup('CheckStore');
var modifieds = grid.getStore().getUpdatedRecords();


var id_check = [];
var ds_check_list = [];
var id_check_type = [];
var id_version = [];

console.log(modifieds);

if (modifieds.length > 0)
{
    for(var i = 0; i < modifieds.length; i++) {

        id_check.push(modifieds[i].get('ID_CHECK'));
        ds_check_list.push(modifieds[i].get('DS_CHECK_LIST'));
        id_check_type.push(modifieds[i].get('ID_CHECK_TYPE'));
        id_version.push(modifieds[i].get('ID_VERSION'));

    }
}

Ext.Ajax.request({
        url: 'URL',
        method: 'POST',
        params: {
            'Param.1': 'Check',
            'Param.2': id_check.toString(),
            'Param.3': ds_check.toString(),
            'Param.4': id_type.toString(),
            'Param.5': id_version.toString()
        }

This works fine. But I want to know and send also the column name which got updated and its previous value.

When I see the console for console.log(modifieds); , I can spot following:

Console

So how do I access this previousValue object in my code? I want to know previous value as well as column name both.

Kindly advise !


Solution

  •     ds_check_list.push(modifieds[i].getPrevious('DS_CHECK_LIST'));
        id_check_type.push(modifieds[i].getPrevious('ID_CHECK_TYPE'));
    

    Ext.data.Model.getPrevious(fieldname) : Object
    This method returns the value of a field given its name prior to its most recent change.

    The Store.getUpdatedRecords() function returns an Ext.data.Model instance, which in turn has a getPrevious method.
    It usually helps a lot to take a look at the API docs of ExtJS and then just navigating through the methods and return values used.
    The getUpdatedRecords() method is documented over here: http://docs.sencha.com/extjs/5.0/5.0.1-apidocs/#!/api/Ext.data.Model-method-getPrevious