Skip to Content
Technical Articles

Handle “DataReceived” Event in Smart Table after version 1.56 in SAPUI5

Handling the events “Data Received” and “Data Requested” is not straight forward, in case of smart tables after Sap UI version 1.56. These events were available before version 1.56, but they are now depreciated since version 1.56. The below blog covers the details of how to handle these events after version 1.56.

Also, if you have worked on versions previous to 1.56, and have used the event “datareceived” or “datarequested” in Smart Tables, for some custom logic, but now after UI upgrade, these events have become obsolete, then you need to do below things, to get your code running after upgrade.

If you see the sap help about these events, then you can find below one liner. Hence I thought of giving a detailed method of implementing these events after version 1.56.

One Liner from Sap Help : “Deprecated as of version 1.56. Use beforeRebindTable event to attach/listen to the binding “events” directly”.

From the above help statement its a little hard to make out, what exactly needs to be done to implement these events.

Before upgrade one could easy specify the “event callback” in a xml view or attach it in the controller. The coding was pretty straight forward. Now its not that straight forward. Hence I thought of writing this blog.

Please find the below 4 steps on how to receive the callback for event “datareceived” in case of smarttables after version 1.56.

1. Implement the event “BeforeRebindTable”

2. Write a generic function “AddBindingListener” to attach event to the binding events.

(see below code snippet). The  generic function is written in your js controller.

          addBindingListener: function(oBindingInfo, sEventName, fHandler) {

oBindingInfo.events = oBindingInfo.events || {};

if (!oBindingInfo.events[sEventName]) {
oBindingInfo.events[sEventName] = fHandler;
} else {
// Wrap the event handler of the other party to add our handler.
var fOriginalHandler = oBindingInfo.events[sEventName];
oBindingInfo.events[sEventName] = function() {
fHandler.apply(this, arguments);
fOriginalHandler.apply(this, arguments);
};
}
},

      3. In the event “BeforeRebindTable”, you can call above generic function to attach the callback.

You need to pass the binding parameters, event name and the callback function name to this  generic method. “_onBindingDataReceivedListener” is the call back function.

this.addBindingListener(oBindingParams, “dataReceived”,                       this._onBindingDataReceivedListener.bind(this));

 

     4. You can write a callback function “_onBindingDataReceivedListener” in your controller, which will give you the requested data.

If you have upgraded recently to a version above 1.56, then you can do the same operations in function _onBindingDataReceivedListener which you had done in the “datareceived” event before upgrade.

 

Thus the above four steps will help you handle the depreciated “datareceived” and “datarequested” events in case of smart tables. The above 4 steps are only applicable if your UI version is more than 1.56. This blog will also help, in case you had handled these events before version 1.56 and now you have recently upgraded to a version higher than 1.56.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.