Keeping modified records of EditorGridPanel while paging

This is an archived post from the ExtJS era — the code may be obsolete, but the principles often still apply.

Code in this post can be obsolete, however, principles and theory may still apply.

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:

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

7 comments

  1. prejiOctober 1, 2009archive
    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 });
  2. SakiOctober 2, 2009archive
    See <a target="_blank" href="http://recordform.learnfromsaki.com" rel="nofollow">RecordForm</a> example, I've copied the code from there. I hope that I haven't made a mistake... ;)
  3. DefaiteNovember 2, 2009archive
    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).
  4. aaaaFebruary 27, 2010archive
    aaaaaaaaaaaaa
  5. Jennifer SuarezApril 7, 2011archive
    Thank you for this! It is exactly what I was looking for.
  6. CoreyMay 25, 2011archive
    I don\'t know why, but I was getting duplicate entries in the modified collection after I page out and page back. Mind you, I\'m doing server-side paging. So after getting the changes on this line: var changes = modified[i].getChanges(); Remove the record like so: store.modified.splice(i, 1); And you\'re sweet! It gets added again when you call set() on the record anyway. Despite the fact I\'d imagine that modified collection is meant to be private/protected, it works.
  7. AnonMay 30, 2011archive
    One note... In 3.3.1 as Corey stated... Duplicates appear in the modified array. The link to the store is being broken simply using the code above. It is very close, but not quite there. The complete code to accomplish this without losing the link is below... var modified = store.getModifiedRecords(); this.modified = []; for (var x = 0; x &lt; modified.length; x++) { var r = store.getById(modified[x].id); if (r) { var changes = modified[x].getChanges(); for (p in changes) { if (changes.hasOwnProperty(p)) { r.set( p, changes[p] ); } } } else { this.modified.push(modified[x]); } }

Comments are closed on archived posts.