Skip to Content
Author's profile photo Pooja Khandhadia

How to deselect checkbox in SAP UI5 table.

Hello folks,

In one of my app I was using sap.m.Table. This table has checkbox to select a particular row. On a click of a button after some functionality I wanted to deselect all the selected checkbox. I found this as a simple solution to do it, hope it helps you too.

In this blog I have explained on how to deselect on the press of a button but this method can also be used on any other events like on navigating to different views or on completing some backend activities the checkbox is deselected.

The xml code will be like:

<Table id=”idChartTable”
 path: ‘oModel>/’
        <Button id="idBtn" text="Terminate"  press="onTerminate"/>
       <Column minScreenWidth="Tablet" id="idInstanceId">
        <Text text="Instance Id"/>
       <Column minScreenWidth="Tablet">
        <Text text="Subject"/>
    <ColumnListItem  class="listitemclass">
       <Text text="{oModel2>id}"/>
       <Text text="{oModel2>subject}"/>

The parameter mode=”MultiSelect” adds the checkbox, we don’t need to code anything more for it.

Now suppose onclick of button whose onPress event is onTerminate following things should happen:
i) ajax call : Calls the api from which data is fetched in the table and terminate the instance in the backend.
ii) Show a message as the instance is terminated.
iii) Deselect the terminated rows.


Controller code:

onTerminate: function(oEvent){
  var oTable = this.getView().byId("idChartTable");
  var oContext = oTable.getSelectedContexts();
  var workInstanceId = [];
  var i = 0;
  var that = this;
     url: URL,
     method: "PATCH",
     dataType: "json",
     contentType :"application/json",
     data: "{\"status\": \"CANCELED\"}",
     headers: {
      "X-CSRF-Token": token
     success: function(){
      console.log("Instance Terminated");
  oTable.removeSelections();"Work Instance Terminated");

Hope this helps you.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Emanuele Ricci
      Emanuele Ricci

      You can improve this tutorial by adding following some best practice.

      First of all, you're using oData/JSON model binding inside your table. You should never update the table rows info manually as you're doing but you should only update the binding itself that will update the table automatically.

      Second of all, you should only update/deselect raws that have been modified (terminated) successfully.

      In this case, you have 2 scenarios:

      • You're using OData and that info will be updated automatically (it's not your case) and you cycle OData response records to only deselect those
      • You are using normal REST/Ajax call so you must loop through the response and check if the record has been terminated. If so you update your JSON Model and uncheck the row's checkbox
      Author's profile photo Pooja Khandhadia
      Pooja Khandhadia
      Blog Post Author

      Thank You Emanuele Ricci for your feedback. I will try to improvise it.