Results 1 to 2 of 2

Thread: Any way to determine if a Store is modified?

  1. #1
    Ext JS Premium Member Gjslick's Avatar
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    129

    Default Any way to determine if a Store is modified?

    Anyone know how to determine if a Store itself is modified? Meaning: if the store has had any models added to it, modified in it, or removed from it?

    It seems I can determine the modified and removed models with getModifiedRecords() and getRemovedRecords(), but I can't determine any added models.

    getNewRecords()
    seems to only return models added to the store which are "new" themselves (i.e. they are phantom records without an id). Can't seem to determine models added to the store which are *not* phantom records (i.e. have an id).

    Also, there's no simple hasChanges() method to go along with commitChanges() and rejectChanges().

  2. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    Try this:
    Code:
    Ext.onReady(function(){
        Ext.define('Override.data.Store', {
            override: 'Ext.data.Store',
            constructor: function(){
                this.callParent(arguments);
                this.setModified(false);
            },
            load: function(){
                this.callParent(arguments);
                this.setModified(false);
            },
            insert: function(){
                this.callParent(arguments);
                this.setModified(true);
            },
            afterEdit: function(){
                this.callParent(arguments);
                this.setModified(true);
            },
            remove: function(){
                this.callParent(arguments);
                this.setModified(true);
            },
            isModified: function(){
                return this._modified;
            },
            setModified: function(flag){
                this._modified = flag;
            }
        });
    
        var store = Ext.create('Ext.data.Store', {
            fields: ['id', 'name'],
            data: [{
                id: 1, name: 'A'
            },{
                id: 2, name: 'B'
            }]
        });
        console.log('load -> modified:', store.isModified());
        
        store.setModified(false);
        store.add({id: 3, name: 'C'});
        console.log('add -> modified:', store.isModified());
    
    
        store.setModified(false);
        store.getAt(0).set({name: 'D'});
        console.log('update -> modified:', store.isModified());
    
    
        store.setModified(false);
        store.removeAt(0);
        console.log('remove -> modified:', store.isModified());
    });

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •