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.

Accepted Solutions (1)

Accepted Solutions (1)

AndreasKunz
Advisor
Advisor

Hi Alex,

I think "addSelectionInterval()" is what you are looking for.

https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.table.Table.html#addSelectionInterval

Regards

Andreas

alex_dim
Explorer
0 Kudos

Hello Andreas,

Thanks for the quick answer. The addSelectionInterval() is not quite what I need because, this function selects all the rows from startIndex to endIndex, so for this example: addSelectionInterval(0,2),  all rows from index 0 to index 2 will be selected. What I need is to select only items from certains positions , not all items beetween those position. So for my previous example, i need to select items from index 0 and index 2, not from index 1 too. I hope I was more clear now.


Best regards

former_member182862
Active Contributor
0 Kudos

Hi Alex

Here is an example. Click on the select button 🙂

-D

alex_dim
Explorer
0 Kudos

Hi Dennis,

I didn't even think at something like that. That's great !

Thank you very much.

P.S. Happy holidays .

Best regards,

Alex

Answers (1)

Answers (1)

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