简体   繁体   中英

sapui5 ui table how to unselect the rows by unchecking the row checkbox

Im facing a small issue in UI table. How can we remove the selected rows if we unselect the checkbox for a row? To get the row data im using below code and it is working fine without any issues.

在此处输入图片说明

getEnterDetailCount:function(oEvent){
            var oRowContext = oEvent.getParameter("rowContext");
            var oContextObject = oRowContext.getObject();
            roomsArray.push(oContextObject);
        };

Using the above method, If i select the row im able to get the Complete Row Data. But if i unselect the row, Still it is considering as a row selection and count is getting increased.

In XML im using rowSelectionChange event to check and uncheck the checkbox on the row

Can someone please help me to fix this issue? Thank you in advance.

Regards, Pavantej

For sap.m.table you can use getSelectedItems to get all selected rows from your table. Loop all selected rows and put them in your array.

getEnterDetailCount:function(oEvent){
  var oContextObject;
  var roomsArray = [];
  var oTable = this.getView().byId("myTable");
  var aSelectedItems = oTable.getSelectedItems();

  aSelectedItems.forEach( function(v,i){
     oContextObject = v.getBindingContext().getObject();
     roomsArray.push(oContextObject);
  });
};

For sap.ui.table you can use getSelectedIndices()

getEnterDetailCount:function(oEvent){
  var oContextObject;
  var roomsArray = [];
  var oTable = this.getView().byId("myTable");
  var aSelectedIndices = oTable.getSelectedIndices();

  aSelectedIndices.forEach( function(v,i){ 
     oContextObject = oTable.getContextByIndex(v).getObject();
     roomsArray.push(oContextObject);
  });
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM