sap.ui.table.Table: Row selections lost after sort or filter
Describe the issue
When using sap.ui.table.Table with MultiSelectionPlugin or the built-in SelectionModelSelection, row selections are cleared on every sort or filter operation.
This is because selections are stored as row indices, which shift after sort/filter. There is no built-in mechanism to preserve selections across these operations.
Steps to reproduce
- Create a
sap.ui.table.TablewithMultiSelectionPlugin - Select several rows
- Sort any column or apply a filter
- Selections are gone
Expected behavior
Row selections should be preserved after sort/filter. The selected rows — identified by their binding context, not their index — should remain selected even after their visual position changes.
Current workaround
I have implemented a community plugin that solves this by tracking binding context paths instead of row indices:
- npm: ui5-plugin-persist-selection
- GitHub: AbhilashBiradar/ui5-plugin-persist-selection
- Live demo: https://abhilashbiradar.github.io/ui5-plugin-persist-selection/demo/index.html
The plugin extends sap.ui.table.plugins.SelectionPlugin (the official base class) and overrides setSelected() / isSelected() to use context paths. It hooks into TableUtils.Hook.Keys.Table.RowsBound and binding change events to re-resolve selections after sort/filter.
Proposal
Consider either:
- Adding a
preserveSelectionproperty toMultiSelectionPluginthat enables context-path-based selection tracking natively - Documenting the recommended approach for selection persistence in the plugin guide
Environment
- UI5 version: 1.64+ (where
SelectionPluginwas introduced) - Affects:
sap.ui.table.Table,TreeTable,AnalyticalTable - Does not affect:
sap.m.Table(different plugin architecture)
Closing as duplicate of #439 which tracks the same issue since 2015. Added a community plugin solution there instead.