Results 1 to 2 of 2

Thread: Persist DataView selections after store reload

  1. #1

    Default Persist DataView selections after store reload

    I've got a datastore who's data needs updating every few seconds. After reloading the store, all my selections get cleared.

    I attempted to extend DataView to do this but it still clears selections that were made between the store's beforeload call and the dataviews refresh call.

    Code:
    AC.PreserveSelectionsDataView = Ext.extend(Ext.DataView,{
        constructor: function(config) {
            var usersPrepareData = AC.PreserveSelectionsDataView.superclass.prepareData;
            if(config.prepareData) {
                usersPrepareData = config.prepareData;
            }
            config = Ext.apply({
                priorSelectedRecordIds: [],
                usersPrepareData: usersPrepareData,
                prepareData: function(data, recordIndex, record) {
    //                console.log("...preparing the datas.", data);
    //                console.log("recordIndex ", recordIndex, " isSelected: ", this.priorSelectedRecordIds.indexOf(record.id)!=-1);
                    if(this.priorSelectedRecordIds && this.priorSelectedRecordIds.indexOf(record.id)!=-1) {
    //                    data["status"] = data["status"]+ " " +this.initialConfig.selectedClass;
                        this.selectedIndexes.push(recordIndex);
                    }
                    return this.usersPrepareData(data, recordIndex, record);
                }
            }, config);
    
    
            AC.PreserveSelectionsDataView.superclass.constructor.call(this, config);
    
    
            this.store.on("beforeload", function(){
                var selectedRecords = this.getSelectedRecords();
                var selectedRecordIds = new Array();
                for(var i=0;i<selectedRecords.length;i++) {
                    selectedRecordIds.push(selectedRecords[i].id);
                }
                this.priorSelectedRecordIds = selectedRecordIds;
                console.log("beforeload priorSelectedRecordIds: ", this.priorSelectedRecordIds);
            },this);
        },
        refresh: function() {
            this.selectedIndexes = new Array();
            AC.PreserveSelectionsDataView.superclass.refresh.call(this, arguments);
            this.select(this.selectedIndexes);
            console.log("refresh getSelectedRecords: ", this.getSelectedRecords());
        }
    
    
    });
    Any suggestions?

  2. #2
    Sencha User
    Join Date
    Jan 2011
    Posts
    549

    Default

    It looks like you're already pretty much there.

    On the beforeload, get the selected records and store them in a var, then on load simply use the dataview's "select" method and pass it the variable you saved on the beforeload.

Tags for this Thread

Posting Permissions

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