1. #1
    Sencha Premium Member
    Join Date
    Mar 2013
    Posts
    42
    Vote Rating
    0
    Answers
    4
    BKrones is on a distinguished road

      0  

    Default Answered: Modify Pullrefresh Plugin

    Answered: Modify Pullrefresh Plugin


    Hi,
    i got a list using Pullrefresh Plugin, but it only refreshes new added records.
    Updated and deleted records are not updated ( only json-data is loaded correctly but not snychronized to current store )

    I found solution to solve delete issue, but i am not able to use this in Sencha Architect:
    Does anyone know the equivalent
    Code:
    Ext.define('TP.extend.override.PullRefresh', {    override: 'Ext.plugin.PullRefresh',
    
        onLatestFetched: function(operation) {
            var store           = this.getList().getStore(),
                oldRecords      = store.getData(),
                old_length      = oldRecords.length,
                newRecords      = operation.getRecords(),
                length          = newRecords.length,
                toInsert        = [],
                newRecordIds    = [],
                oldRecordsArr   = [],
                toRemove        = [],
                newRecord, newRecordIndex, oldRecord, i;
    
            for (i = 0; i < length; i++) {
                newRecord = newRecords[i];
                oldRecord = oldRecords.getByKey(newRecord.getId());
    
                newRecordIds.push(newRecord.getId());
    
                if (oldRecord) {
                    oldRecord.set(newRecord.getData());
                } else {
                    toInsert.push(newRecord);
                }
    
                oldRecord = undefined;
            }
    
            store.insert(0, toInsert);
            oldRecordsArr = store.getRange();
            for (i = 0; i < old_length; i++) {
                oldRecord = oldRecordsArr[i];
                newRecordIndex = newRecordIds.indexOf(oldRecord.getId());
    
                if (newRecordIndex == undefined || newRecordIndex == -1) {
                    toRemove.push(oldRecord);
                }
    
                oldRecord = undefined;
            }
            store.remove(toRemove);
        }
    });

  2. Right click on the Plugin in the toolbox, click Create Override.

    Then put the updated code in the override. This will change all of the PullRefresh instances to use the new code you've provided. Mind you when using overrides like this you will need to make sure the code is updated to work with the latest code whenever you update the library.

  3. #2
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,399
    Vote Rating
    128
    Answers
    68
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Right click on the Plugin in the toolbox, click Create Override.

    Then put the updated code in the override. This will change all of the PullRefresh instances to use the new code you've provided. Mind you when using overrides like this you will need to make sure the code is updated to work with the latest code whenever you update the library.
    Aaron Conran
    @aconran
    Sencha Architect Development Team

Thread Participants: 1