1
votes

I have store not connected to any server. The store is attached to grid and i add records to it in various places in my app. Is is possible not to allow to add records that already exists? I am using idProperty but it is not working (propably because store is not connected to server?). I already got something like this:

Ext.define('GSIP_PLANY.grid.store.ParcelStore',{
    extend: 'Ext.data.Store',
    model: 'GSIP_PLANY.grid.model.ParcelModel',
    listeners:{
        add:function(store, records, index, eOpts) {        
            for (var i in records) {
                var idx = store.findExact('name', records[i].get('name'));
                if ( idx != -1 && idx < index) {
                    store.remove(records[i]);
                }
            }
        }
    }
});

The above code checks if there is similar record that was inserted earlier and if yes, it removes the new record. The problem is i also have remove event handlers attached to store, which are fired in above code, causing removal of record (based on its name) in other places of my app. I simply want not to store records that already exists. Something like beforeadd event would be great but there is no such event.

And my model definition:


    Ext.define('GSIP_PLANY.grid.model.ParcelModel',{
        extend: 'Ext.data.Model',
        fields: ['id', 'name', 'tract', 'mapSheet', 'district', 'buildingNumber', 'streets', 'place'],
        idProperty:'name'
    });

The idProperty is not working as i can add as many records with same name as i want. Any ideas?

1

1 Answers

1
votes

Ext.data.Store has suspendEvents() and resumeEvents() methods (inherited from Ext.util.Observable mixin), which will let you omit the triggering of remove event.