简体   繁体   中英

sapui5 sap.ui.table How to uncheck the checkbox of table row programatically

Im facing a small issue in sap.ui.table . I want to uncheck the checkbox of the table if i delete the record. Here im able to delete the record, But the selection of checkbox was not getting cleared and it is appending for the below row. 在此处输入图片说明

In the above image if you see, if i delete "Rani Test" , Rani Test row will get deleted but checkbox will get selected to "Surya Test" . Please check the below code..

onPressDelete: function(evt) {
            var deleteRecord = evt.getSource().getBindingContext('familyDetailsModel').getObject();
            var tableId = this.getView().byId("familyDetailsModel");
            var index = tableId.getSelectedIndex();          
            //this.getView().byId("familyDetailsModel").removeSelectionInterval(index,1);

                for (var i = 0; i < this.getView().getModel('familyDetailsModel').getData().length; i++) {
                    if (this.getView().getModel('familyDetailsModel').getData()[i] == deleteRecord) {
                        this.getView().byId("familyDetailsModel").removeSelectionInterval(i, i);
                        this.getView().getModel('familyDetailsModel').getData().splice(i, 1);
                        this.getView().getModel('familyDetailsModel').refresh();
                        break;
                    }


            }
        },

In the above code, splice() method im using to delete the row which is working perfectly. But checkbox is not getting deselected. To uncheck the checkbox im trying with removeSelectionInterval() method. But it is not behaving as expected.

Can someone please help me to sort this issue

Thanks in advance

This line var index = tableId.getSelectedIndex(); returns -1 in your scenario. Furthermore, to delete one line you need to specify removeSelectionInterval(index,index); The second parameter is not the number of positions to delete. Is the indexTo , so you want to remove from the selected row, to the selected row.

Getting the row index from the event will work better for you. Try this:

var iIndex = oEvent.getSource().getParent().getIndex();
var oTable = this.getView().byId("__table0");
oTable.removeSelectionInterval(iIndex, iIndex);

Here the snippet: https://plnkr.co/edit/wkMc4LcjYYS3K73ClYUc?p=preview

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