remember after refresh selected row in extjs grid

后端 未结 5 1574
借酒劲吻你
借酒劲吻你 2020-12-17 14:56

I have a problem. I use extjs grid. This grid will be refreshed every seconds.

I refresh with this function:

ND.refresh =          


        
5条回答
  •  情话喂你
    2020-12-17 15:27

    I wrote simple Ext.grid.Panel extension that automatically selects back rows that were selected before store reload. You can try it in this jsFiddle

    Ext.define('PersistantSelectionGridPanel', {
        extend: 'Ext.grid.Panel',
        selectedRecords: [],
        initComponent: function() {
            this.callParent(arguments);
    
            this.getStore().on('beforeload', this.rememberSelection, this);
            this.getView().on('refresh', this.refreshSelection, this);
        },
        rememberSelection: function(selModel, selectedRecords) {
            if (!this.rendered || Ext.isEmpty(this.el)) {
                return;
            }
    
            this.selectedRecords = this.getSelectionModel().getSelection();
            this.getView().saveScrollState();
        },
        refreshSelection: function() {
            if (0 >= this.selectedRecords.length) {
                return;
            }
    
            var newRecordsToSelect = [];
            for (var i = 0; i < this.selectedRecords.length; i++) {
                record = this.getStore().getById(this.selectedRecords[i].getId());
                if (!Ext.isEmpty(record)) {
                    newRecordsToSelect.push(record);
                }
            }
    
            this.getSelectionModel().select(newRecordsToSelect);
            Ext.defer(this.setScrollTop, 30, this, [this.getView().scrollState.top]);
        }
    });
    

提交回复
热议问题