1. #11
    Sencha User
    Join Date
    Sep 2011
    Posts
    60
    Vote Rating
    3
    janelle is on a distinguished road

      3  

    Default

    Here it is wrapped in an override so you dont have to change your ST library

    Put this in app/ux/WebStorage.js
    Code:
    Ext.define('app.ux.WebStorage', {
        override: 'Ext.data.proxy.WebStorage',
        
        read: function(operation, callback, scope) {
            //console.log('in custom WebStorage.read()');
            var records    = [],
                ids        = this.getIds(),
                model      = this.getModel(),
                idProperty = model.getIdProperty(),
                params     = operation.getParams() || {},
                length     = ids.length,
                i, record, filters, tmpRecords = [];
    
            filters = operation.getFilters() || [];
    
            //read a single record
            if (params[idProperty] !== undefined) {
                record = this.getRecord(params[idProperty]);
                if (record) {
                    tmpRecords.push(record);
                    //operation.setSuccessful();
                }
            } else {
                for (i = 0; i < length; i++) {
                    tmpRecords.push(this.getRecord(ids[i]));
                    //operation.setSuccessful();
                }
            }
            
            // remove items that dont match filter
            if(filters.length > 0)
            {
                for(i = 0; i < tmpRecords.length; i++)
                {
                    var add = true;
                    
                    for(var x = 0; x < filters.length; x++)
                    {
                        if(tmpRecords[i].data[filters[x]._property] != filters[x]._value)
                        {
                            add = false;
                        }
                    }
                    
                    if(add)
                    {
                        records.push(tmpRecords[i]);
                    }
                }
            }
            else
            {
                records = tmpRecords;
            }
            
            if(records.length > 0)
            {
                operation.setSuccessful();
            }
    
            operation.setCompleted();
    
            operation.setResultSet(Ext.create('Ext.data.ResultSet', {
                records: records,
                total  : records.length,
                loaded : true
            }));
            operation.setRecords(records);
    
            if (typeof callback == 'function') {
                callback.call(scope || this, operation);
            }
        }
    });
    Put this in your app.js before your Ext.application() definition.
    Code:
    Ext.require('app.ux.WebStorage');

  2. #12
    Sencha User
    Join Date
    Sep 2011
    Posts
    60
    Vote Rating
    3
    janelle is on a distinguished road

      0  

    Default

    In another place in my code, I am updating the data in one of the related items.

    The sync function was not working, and after looking at the objects, the dirty flag (before sync) was false. So I set the dirty flag to true manually, and the sync worked fine.



    Is it normal that we have to set the dirty flag manually when changing a value in a store??
    I would expect that to all be handled by sencha.

  3. #13
    Sencha Premium Member StuartAshworth's Avatar
    Join Date
    Feb 2009
    Location
    Glasgow, Scotland
    Posts
    358
    Vote Rating
    19
    StuartAshworth will become famous soon enough StuartAshworth will become famous soon enough

      0  

    Default

    Hi Janelle,

    Thanks for this override it works a treat!

    Do you know if this has been raised as a proper bug? I have some standalone code that reproduces it which I can supply so the devs can see it happening and hopefully add your fix.

    Thanks again!

    Stuart
    Want to build better Sencha apps? Check out my free email course Best Practices for Improving your Sencha Apps

    Learn Ext JS 6 with my new ebook - Ext JS 6: Getting Started. Use code "extjs6" for 33% off!

    Need help with Sencha development, code reviews or training? Get in touch!

    stuart@stuartashworth.com
    @StuartAshworth9

  4. #14
    Sencha Premium Member StuartAshworth's Avatar
    Join Date
    Feb 2009
    Location
    Glasgow, Scotland
    Posts
    358
    Vote Rating
    19
    StuartAshworth will become famous soon enough StuartAshworth will become famous soon enough

      0  

    Default

    Hi

    I've been using Janelle's fix in my project and think I have come across an issue.

    The setSuccessful call which is only fired when there are records present (i.e. not being filtered out) means that a dataview bound to the store being loaded won't be refreshed to reflect the new records.

    In my case I was deleting a record and reloading this association's store and finding the dataview wasn't refreshed.

    In my opinion the setSuccessful should still be called as the load was successful it just happened to load zero records. I have removed the surrounding condition and it seems to be working as expected now.

    Cheers
    Stuart
    Want to build better Sencha apps? Check out my free email course Best Practices for Improving your Sencha Apps

    Learn Ext JS 6 with my new ebook - Ext JS 6: Getting Started. Use code "extjs6" for 33% off!

    Need help with Sencha development, code reviews or training? Get in touch!

    stuart@stuartashworth.com
    @StuartAshworth9

  5. #15
    Sencha User
    Join Date
    Aug 2011
    Location
    Netherlands
    Posts
    7
    Vote Rating
    0
    Meindert Kuyvenhoven is on a distinguished road

      0  

    Default

    Brilliant! After a long search, this simple solution made my day