简体   繁体   English

sapui5 ui表如何通过取消选中行复选框来取消选择行

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

Im facing a small issue in UI table. 我在UI表中面临一个小问题。 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 在XML im中,使用rowSelectionChange事件来检查和取消选中行上的复选框

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. 对于sap.m.table ,可以使用getSelectedItems从表中获取所有选定的行。 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() 对于sap.ui.table ,可以使用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);
  });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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