cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 ui table set row selection set programtically

vinodkumar_thangavel
Participant
0 Kudos
1,523

Hi Experts,

I am using sap.ui.table.Table and I am trying to set the check box selection programmatically using the below code ,

I am able to see the check box being selected during the debug session but its getting cleared after that. Can you please let know am I missing any thing here.

var rows = this.getView().byId("Table").getRows()[1];

rows._setSelected(true);

Thanks,

Vinodkumar.

View Entire Topic
leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vinodkumar,

The reason that the checkbox selection is getting cleared after the debug session is because the _setSelected method is a private method of the sap.ui.table.Row class and is not intended to be called directly by application code.

Instead, you can use the setSelectedIndex method of the sap.ui.table.Table control to programmatically select rows in the table.

var oTable = this.getView().byId("Table"); 
var oRow = oTable.getRows()[1]; 
oTable.setSelectedIndex(oRow.getIndex()); 

To select multiple rows, you can pass an array of row indices to the setSelectedIndices method instead.

vinodkumar_thangavel
Participant

Thank You very much 🙂

Marco_DiPisello
Explorer
0 Kudos
setSelectedIndices return this error VM4594:1 Uncaught TypeError: oTable.setSelectedIndices is not a function