openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

sap.ui.table.Table: Row selections cleared after applying a sort or filter

Open cmastrandrea opened this issue 11 years ago • 19 comments

OpenUI5 version: latest

Browser/version (+device/version): all

Any other tested browsers/devices(OK/FAIL):

URL (minimal example if possible): http://jsbin.com/habapa/edit?html,js,output

User/password (if required and possible - do not post any confidential information here):

Steps to reproduce the problem:

  1. Select one or more rows in the table
  2. Click on a column header and select one of the sort options
  3. Note that the row selections are cleared
  4. Repeat the same and apply a filter (e.g. text) and note that the row selections are cleared again.

What is the expected result? Expected that if you're resorting a table, any row selections will be maintained after the sort. For filtering, it's expected that any selected rows that make it through the filter remain selected.

What happens instead? All row selections are cleared after a resort or filter.

Any other information? (attach screenshot if possible)

cmastrandrea avatar May 15 '15 17:05 cmastrandrea

This works (currently) as designed (see here), because preserving the selection is not so easy to implement.

I fully agree that this would be a nice feature, but it is currently not planned from our side. I will keep this open as an enhancement for now.

matz3 avatar May 19 '15 12:05 matz3

Thanks for the info Matthias. The unfortunate reality is that most users likely expect this behavior, and so all OpenUI5 app creators that want to address this expectation need to tackle this "not so easy" task on their own in varying ways. Any additional consideration for this making it into the plan would be greatly appreciated.

cmastrandrea avatar May 19 '15 12:05 cmastrandrea

I can fully understand you. I've forwarded your request. Let's see if it gets into the backlog in the future. @thomaskoetter we should make sure to update this issue once there is some progress going on.

matz3 avatar May 20 '15 13:05 matz3

All I'm trying to say is that most users expect table selections to remain in place after a sort or filter. And so anyone writing an OpenUI5 app would need to add in this support on their own. Which means alot of duplicate effort in researching/implementing a solution. Having this in the SDK would spare each developer of that and provide a consistent and tested solution.

cmastrandrea avatar May 20 '15 13:05 cmastrandrea

Fully understood. Both use cases are valid. It's been added to the backlog, but there's no saying when it will make the cut.

thomaskoetter avatar May 20 '15 14:05 thomaskoetter

Just checking to see if there's any realistic chance this will make it out of the backlog in the near future. This is an issue that keeps coming up from our consumers, and we'll need to come up with a solution if one isn't provided in the SDK.

cmastrandrea avatar Jan 26 '16 14:01 cmastrandrea

Hello cmastandrea, i contacted the product owner for this team again to give a feedback.

Michadelic avatar Jan 29 '16 14:01 Michadelic

Hi Matthias, Is this enhancement (Row selections cleared after applying a sort or filter) has been implemented in sap.ui.table,Table ?

venkymachineni avatar May 11 '17 09:05 venkymachineni

Hi @venkymachineni i have extended this and solved issue. @matz3 I would love to contribute this feature.

AbhilashBiradar avatar Jul 31 '18 05:07 AbhilashBiradar

Hi @simlin, is there any status update on this issue? I have the same problem, that my table looses the value of the checkboxes. I also noticed, that it already is implemented in the m.table.

crossfader92 avatar Feb 06 '20 11:02 crossfader92

Hi @crossfader92 , keeping the selection information after sort or filter needs a key based approach instead of an index based API. Or the new indices must be recalculated after sort or filter. For this the full information (data) must be available which is mostly only the case with ClientListBindings. So an "one selection API fits all cases" seems not to be the way forward. Therefore we started with the MultiSelectionPlugin to introduce a way to provide alternative selection behaviors more easily. We are not yet there to open it up for "external" plugins. But that's the idea for future plannings.

simlin avatar Feb 14 '20 11:02 simlin

Hi Guys,

came across this by chance, because I had some handling issues with row selection.

I see that it is quite difficult to preserve the selection, especially in lazy loading scenarios. So. it would have to be handled by the dev who implements it.

However, in case of multi select I don't see an obvious way to re-apply the selection after update.

Would it make sense to implement a counterpart "sap.ui.table.setSelectedIndices" for the method "sap.ui.table.getSelectedIndices"?

Best, Pablo

PabloMizzle avatar Apr 06 '20 08:04 PabloMizzle

Hi Pablo, there are the two methods "addSelectionInterval" and "setSelectionInterval". I think that's what you need :) I fixed the selection issue for me be redefining the onRowsUpdated method of sap.ui.table. But that's hopefully just a temporary solution. Regards, Kevin

crossfader92 avatar Apr 06 '20 09:04 crossfader92

Thanks for the hint @crossfader92, that's what I was looking for!

PabloMizzle avatar Apr 06 '20 10:04 PabloMizzle

Sorry for chiming in, but isn't adding an extra column with a CheckBox and a binding to a model column a possible stand-in for using the multiselect mode for these kinds of use cases?

Just a thought as I ran into the same question today and solved it this way.

wernerdaehn avatar Jul 06 '20 11:07 wernerdaehn

Backlog FIORITECHP1-14428

simlin avatar May 04 '22 15:05 simlin

Hello we cross with this issue as well any progress or temporary solution other than getSelectedIndices, .setSelectionInterval methods?

loatherer avatar Jun 21 '24 12:06 loatherer

For anyone still hitting this in 2026 — I've published a community plugin that solves this by tracking binding context paths instead of row indices:

It extends the official sap.ui.table.plugins.SelectionPlugin base class (available since UI5 1.64) and overrides setSelected() / isSelected() to use context paths. Works with OData and JSON models, supports MultiToggle and Single modes, and is compatible with all sap.ui.table.Table variants.

// Just add it as a dependent — no other config needed
oTable.addDependent(new PersistSelectionPlugin());

Selections survive sort, filter, and pagination. The selectionChange event returns contextPaths (stable across sort/filter) in addition to rowIndices.

AbhilashBiradar avatar Jul 28 '26 02:07 AbhilashBiradar

Hello @AbhilashBirada

Thank you for the contribution.

The shown solution uses the same mechanism as the ResponsiveTable to remember the binding paths to keep the selection. This works well with client-side models (JSONModel), but it has weak points with ODataV2, mainly because contexts are not preserved on any model refresh.

For ODataV4, UI5 offers two dedicated plugins that leverage model capabilities to solve the sort topic and keep selected contexts alive during refresh:

  • sap.ui.table.plugins.ODataV4MultiSelection (https://sdk.openui5.org/#/api/sap.ui.table.plugins.ODataV4MultiSelection) for multi-selection scenarios
  • sap.ui.table.plugins.ODataV4SingleSelection (https://sdk.openui5.org/#/api/sap.ui.table.plugins.ODataV4SingleSelection) for single-selection scenarios

These plugins utilize ODataV4's model capabilities to maintain selection state across operations like sorting and refreshing. The same model functionality is also used by the ResponsiveTable in combination with ODataV4, providing a consistent approach across table types.

We recommend using these ODataV4-specific plugins for robust selection persistence when working with ODataV4 models.

simlin avatar Jul 30 '26 11:07 simlin