Gowtham Kesa
Gowtham Kesa

Reputation: 99

How to retrieve the rows which are selected in the list report page of smart templates

This is the List Report type of Smart Template application enter image description here

Here I have selected 2nd and 5th row, I also have a button named Send Requests in the section part which is highlighted. If I click this button it calls a javascript controller function which is defined in the extensions of the application. In this js function how can I retrieve the selected rows that are selected?

I have enabled the checkboxes in this page by mentioning this code

"settings": { "gridTable": false, "multiSelect": true } in the manifest.json

As it was recommended by this link https://sapui5.netweaver.ondemand.com/#docs/guide/116b5d82e8c545e2a56e1b51b8b0a9bd.html

I want to know how can I retrieve the rows which got selected?

Upvotes: 2

Views: 10123

Answers (3)

Sebastiano Marchesini
Sebastiano Marchesini

Reputation: 11

If you use smart template create an extension.

This is the standard event befor the table is rebinding:

onBeforeRebindTableExtension: function (oEvent) {
            this._table = oEvent.getSource().getTable();
        }

In your action function (or where you want) call the table and get the context :

this._table.getSelectedContexts();

Upvotes: 1

suryabhan mourya
suryabhan mourya

Reputation: 287

In this type of table there is way.

var myTable=sap.ui.getCore().byId("your table id");

get all rows:

var myTableRows=myTable.getRows();

now get selected Indices

var selectedIndeices=myTable.getSelectedIndices(); //this will give you array of indeices.

now run loop on indeices array. And get particular row item; // get binding path

 var bindingpath=myTableRows[2].getBindingContext().sPath; // this will return eg:"/ProductCollection/2"

// now get Binding object of that particular row.

var myData=myTableRows[2].getModel().getObject(bindingpath); // this will return binding object at that perticular row.

// once your loop is over in the end you will have all object of selected row. then do whatever you want to do.

Upvotes: 2

Serban Petrescu
Serban Petrescu

Reputation: 5206

There is an API that you can use for your use case. It is described here: https://sapui5.netweaver.ondemand.com/#docs/guide/bd2994b69ef542998becbc69ab093f7e.html

Basically, you just need to call the getSelectedContexts method. Unfortunately you will not be able to really get the items themselves, only the binding contexts (which point to the data entities which are selected). Excerpt from the documentation:

After you have defined a view extension, you can access and modify the properties of all UI elements defined within these extensions (for example, change the visibility). However, you cannot access any UI elements that are not defined within your view extensions.

Upvotes: 2

Related Questions