Learn from Saki

Knowledge is power

This content is for registered users only. Please login.
Hello! To access your account, please Log in. Not a member? Sign up
  • Videos
  • Blog
  • Examples
  • Services
  • Add-ons
  • About

Keeping modified records of EditorGridPanel while paging

September 28, 2009 by saki 7 Comments

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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.
  • Author
  • Recent Posts
Follow me:
saki
I'm a well seasoned developer, consultant and educator of web applications based mainly on Sencha libraries, PHP, MySQL and Node.js. Besides (Apple) computers, I love photography and mountain biking.
Follow me:
Latest posts by saki (see all)
  • Ext, Angular, React, and Vue - June 27, 2019
  • The Site Resurgence - February 11, 2018
  • Configuring ViewModel Hierarchy - June 19, 2015

Filed Under: ExtJS Tagged With: deprecated, extjs, grid, Know-how, pattern

Comments

  1. preji says

    October 1, 2009 at 12:27 pm

    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
    });

    Log in to Reply
  2. Saki says

    October 2, 2009 at 9:36 am

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

    Log in to Reply
  3. Defaite says

    November 2, 2009 at 8:31 pm

    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).

    Log in to Reply
  4. aaaa says

    February 27, 2010 at 1:01 pm

    aaaaaaaaaaaaa

    Log in to Reply
  5. Jennifer Suarez says

    April 7, 2011 at 5:52 pm

    Thank you for this! It is exactly what I was looking for.

    Log in to Reply
  6. Corey says

    May 25, 2011 at 8:43 am

    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.

    Log in to Reply
  7. Anon says

    May 30, 2011 at 7:18 am

    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 < 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]); }
    }

    Log in to Reply

We will be happy to hear back from you Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories

  • Addons (2)
  • Architecture (14)
  • Examples (2)
  • ExtJS (26)
  • Howtos (16)
  • Javascript (1)
  • Know-how (32)
  • Linux (1)
  • Mac OS X (2)
  • SASS/CSS (2)
  • Snippets (9)
  • Theory (14)
  • Touch (6)
  • Tutorials (5)
  • What is a … (9)

Tag cloud

abstract class accordion application button class cluster column component config css definition deprecated design education event example extension extjs factory function form grid html initComponent items javascript Know-how knowledge layout Linux listener mysql old panel pattern php plugin render snippet sql sqlite state table touch tree viewpoint

Membership

Become a Member
Affiliate Program

Support

FAQ
Contact

Legal

Terms and Conditions
Licensing
Privacy Policy

Copyright © 2021 · Dynamik-Gen on Genesis Framework · WordPress · Log in