0
votes

I have the issue that the pressItem event is triggered twice at smarttable ( sapui5).

The smarttable has type ResponsiveTable.

 onAfterRendering : function(){
        var tTable = this.byId("LineItemsSmartTable");
        var oTable = this.byId("LineItemsSmartTable").getTable(); 
        oTable.setMode(sap.m.ListMode.SingleSelectMaster);
        oTable.onAfterRendering = function(){
          this.attachItemPress(function(oEvent){ alert( "Pressed" ); });
        };
            
        //	var fnItemPress = function(){ alert("press2") };   
        tTable.attachDataReceived(function(){
             var aItems = oTable.getItems();
             if(aItems.length === 0 ) return;
             $.each(aItems, function(oIndex, oItem) {
                //oItem.detachPress(fnItemPress);
                 oItem.setType("Active");
          //	oItem.attachPress(fnItemPress);
            });
			 });
}
    
1

1 Answers

0
votes

If onAfterRendering is not being called already onInit then reconsider renaming the function oTable.onAfterRendering.

onAfterRendering is already called in the controller lifecycle, you could try creating a new function and then calling that in onAfterRendering.

See this answer

onAfterRendering: function() {
    this.tableItems();
  },

  tableItems: function() {
    var tTable = this.byId("LineItemsSmartTable");
    var oTable = this.byId("LineItemsSmartTable").getTable();
    oTable.setMode(sap.m.ListMode.SingleSelectMaster);

    oTable.attachItemPress(function(oEvent) {
      alert("Pressed");
    });

    tTable.attachDataReceived(function() {
      var aItems = oTable.getItems();
      if (aItems.length === 0) return;
      $.each(aItems, function(oIndex, oItem) {
        oItem.setType("Active");
      });
    });

  }