Keeping modified records of EditorGridPanel while paging

28. September 2009 – 10:59

If you modify records of an editable grid with paging and if you then page-out, your changes are lost. Well, they are not lost in fact unless you have set pruneModifiedRecords:true on the strore. The modifications are still available so we just need to apply them. Here is the code fragment that does it:

var grid = new Ext.grid.EditorGridPanel({
    store:new Ext.data.Store({
         listeners:{
            load:{scope:this, fn:function(store) {
 
                // loop through modified records
                var modified = store.getModifiedRecords();
                for(var i = 0; i < modified.length; i++) {
 
                    // see if we have a record with same id 
                    // and apply changes if yes
                    var r = store.getById(modified[i].id);
                    if(r) {
                        var changes = modified[i].getChanges();
                        for(p in changes) {
                            if(changes.hasOwnProperty(p)) {
                                r.set(p, changes[p]);
                            }
                        } // eo changes loop
                    }
                } // eo modified loop
            }} // eo load listener
        } // eo listeners
 
        // rest of store configuration
 
    })
 
    // rest of grid configuration
 
}) // eo grid

pruneModifiedRecords must be false (the default) for this to work.


StumbleUpon Toolbar
  1. 4 Responses to “Keeping modified records of EditorGridPanel while paging”

  2. Am using below code but the data is not retaining while moving to another page

    var dsnew = new Ext.data.Store({
    proxy: new Ext.data.PagingMemoryProxy(dsgrid.reader.arrayData),
    remoteSort: true,
    pruneModifiedRecords :false,
    reader: new Ext.data.ArrayReader({},
    [
    {name: 'IsSlected',type: 'bool'},
    {name: 'RecNo',type: 'int'},

    ]),
    listeners:{
    update:{scope:this, fn:function(store) {
    var modified = store.getModifiedRecords();
    for(var i = 0; i < modified.length; i++) {
    var r = store.getById(modified[i].id);
    if(r) {
    var changes = modified[i].getChanges();
    for(p in changes) {
    if(changes.hasOwnProperty(p)) {
    r.set(p, changes[p]);

    dsnew.refresh;
    }
    } // eo changes loop
    }
    } // eo modified loop
    }} // eo load listener
    } // eo listeners
    });

    By preji on Oct 1, 2009

  3. See RecordForm example, I’ve copied the code from there. I hope that I haven’t made a mistake… ;)

    By Saki on Oct 2, 2009

  4. You can modify this line :

    var r = store.getById(modified[i].id);

    by your own adaptation if you are an unique colum id :

    var r = store.getAt(store.find(\’name\’, modified[i].data.name)) ;

    Saki, modified[i].id, is changed after each loading (firebug).

    By Defaite on Nov 2, 2009

  5. aaaaaaaaaaaaa

    By aaaa on Feb 27, 2010

Post a Comment

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a