PDA

View Full Version : [CLOSED] Supress the select event triggered by SelectionMemory



bogc
Feb 14, 2013, 8:05 PM
My question is related to this post: http://forums.ext.net/showthread.php?21213-Suppress-select-and-deselect-events-when-selection-memory-is-working, but I am not entirely sure it applies in my context.

When the store loadRawData is called, the loadRecords function fires a datachanged event which fires the SelectionMemory plugin memoryRestoreState function, which will fire a select event. I want to supress this selection event. Should I just set the selectionMemoryEvents config to false on the grid? It seems to do the trick, but could you please confirm this approach?


.CustomConfig(cfgs => cfgs.Add(new ConfigItem("selectionMemoryEvents", "false", ParameterMode.Raw)))

Are there any downsides to doing this?

For your convenience I included the source code below:



loadRawData : function(data, append) {
var me = this,
result = me.proxy.reader.read(data),
records = result.records;

if (result.success) {
me.totalCount = result.total;
me.loadRecords(records, append ? me.addRecordsOptions : undefined);
me.fireEvent('load', me, records, true);
}
},



memoryRestoreState : function () {
if (this.store !== null) {
var i = 0,
sel = [],
all = true,
cm = this.headerCt;

if (this.selModel.isLocked()) {
this.wasLocked = true;
this.selModel.setLocked(false);
}

if (this.selModel instanceof Ext.selection.RowModel) {
this.store.each(function (rec) {
var id = rec.getId();

if ((id || id === 0) && !Ext.isEmpty(this.selectedIds[id])) {
sel.push(rec);
} else {
all = false;
}

++i;
}, this);

if (sel.length > 0) {
this.surpressDeselection = true;
this.selModel.select(sel, false, !this.grid.selectionMemoryEvents);
this.surpressDeselection = false;
}
} else {
this.store.each(function (rec) {
var id = rec.getId();

if ((id || id === 0) && !Ext.isEmpty(this.selectedIds[id])) {
var colIndex = cm.getHeaderIndex(cm.down('gridcolumn[dataIndex=' + this.selectedIds[id].dataIndex +']'))
this.selModel.setCurrentPosition({
row : i,
column : colIndex
});
return false;
}

++i;
}, this);
}

if (this.selModel instanceof Ext.selection.CheckboxModel) {
if (all) {
this.selModel.toggleUiHeader(true);
} else {
this.selModel.toggleUiHeader(false);
}
}

if (this.wasLocked) {
this.selModel.setLocked(true);
}
}
},

onMemoryClear : function () {
this.selectedIds = {};
}
});

Thank you

Baidaly
Feb 15, 2013, 2:43 AM
Hello!

Yes, you can do this. Why do you use CustomConfig when you can use

.SelectionMemoryEvents(false)?

bogc
Feb 15, 2013, 3:15 AM
Thanks, yes, I will use .SelectionMemoryEvents(false).