PDA

View Full Version : Store Reload does not clear selections of related grid



Z
Oct 15, 2020, 12:22 AM
Grid1 has Store1 and row selection model

load the grid, check a box

now call this



App.Store1.load({
scope: this,
callback: function(records, operation, success) {
}
});

i would assume calling load would clear selections but it does not.
i need to call this manually.


App.Grid1.getSelectionModel().clearSelections()



Thanks
/Z

fabricio.murta
Oct 15, 2020, 8:52 PM
Hello @Z!

Your thought makes sense. New data, new selection. No guarantee what's selected will still be selectable across loads.

Yet, in the grid panel logic, or rather, selection model logic, the selected records are stored separately so when a reload/refresh happens the selection may be maintained or restored (for instance, when you want to preserve selection across sessions or over pages in paging grids). Thus, even if you're not saving a session, cookies, but still are on the same session/tab when data is refreshed, as long as the saved selection matches reloaded records they'd get selected again while rebuilding the grid.

Thus, if you really want to reset selection, the way you're doing is almost the best route. The method you pointed is private in Ext JS framework (https://docs.sencha.com/extjs/7.2.0/classic/Ext.selection.RowModel.html#method-clearSelections), so you are encouraged not to use it, in favor of its public counterpart (https://docs.sencha.com/extjs/7.2.0/classic/Ext.selection.RowModel.html#method-deselectAll), deselectAll().

This behavior may also depend on what specific selection model you are using in your grid panel. Depending on it it may deselect all on store reload without the need of an external stimulus. This is just a possibility, I didn't check every selection model to ensure which ones do or do not keep selection across reloads.

Hope this helps!