cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - Table, select multiple rows programmatically.

alex_dim
Explorer
0 Kudos

Hello everyone,

I currently have an sap.ui.table with selection mode set to sap.ui.table.SelectionMode.MultiToggle and selection behavior to sap.ui.table.SelectionBehavior.Row.

My question is if there is any way I can programmatically(not by clicking on the table rows) select more than 1 row from the table. For example when the selection mod is set to sap.ui.table.SelectionMode.Single , i can use the setSelectedIndex(index).At first, I was expecting that setSelectedIndex(index) will add the row to the currently selected rows, but it just erase all previously selections and selects the current row.

Is there any workaround for this? Thank you.

View Entire Topic
ralfhasemann
Discoverer
0 Kudos

And what if I don't want to select a block of rows?

draysams
Advisor
Advisor
0 Kudos

ralfhasemann the method signature reads:

addSelectionInterval(iIndexFrom, iIndexTo)

In case of a single selection, only iIndexTo is added to the selection.

You could write something like

tableVariable.addSelectionInterval(rowToBeSelectedVariable, rowToBeSelectedVariable);
haemma83
Active Participant

But this just selects intervals 1-x .. what about if I want to select 1, 5, 7 etc? a given sequence..

0 Kudos

We currently face a similar issue where we need to select for example rows 1, 3, 5 etc.

Any sugesstion?

txemapar
Participant

Hi, we have come in to a provisional solution.

The only method available in the TreeTable library that is able to set indexes without overwriting the previous selections is table.addSelectionInterval(0, 0), lk with that command you can add to the selection index the one in the 0 position.

Be aware that a bug is present in this work-flow, an infinite loop will be created, to prevent this use the command like this:

setTimeout( () => {linesTable.addSelectionInterval(0, 0)}, 1000 );

This is not a very clean solution but is the only way to make that posible nowadays, hope this help you and willing that sapui5 will resolve that issue.

Kind Regards,

Novotic-team

Marco_DiPisello
Discoverer
0 Kudos
unlike setSelectedIndex , you can use addSelectionInterval several times and each set won't erase the previous sets