14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

13

SAPUI5

You code the onSearch function in Listing 13.18, and as you can see, you’re not

passing very much into the boilerplate code. You say what field you want to filter

on (monster name, in this case). In th e second part, you say what table you’re

talking about from the view (the table of monsters). The other two input parameters

are generic values.

In the first part of Listing 13.18, the variable SQUERY is filled with the contents of

the search box. If there is anything in the box, then the filter object is filled with

a list of all monsters whose names contain the value in the search box. In the second

part, the result list is retrieved into variable OTABLE, and that table is filtered

by the filter object created in the first half of the listing.

onSearch: function(oEvent) {

// add filter for search

var aFilters = [];

var sQuery = oEvent.getSource().getValue();

if (sQuery && sQuery.length > 0) {

var filter = new sap.ui.model.Filter("Name",

sap.ui.model.FilterOperator.Contains, sQuery);

aFilters.push(filter);

}

// update list binding

var oTable = this.getView().byId("idMonstersTable");

var binding = oTable.getBinding("items");

binding.filter(aFilters, "Application");

},

Listing 13.18 Coding the onSearch Event Handler

Defining the Dialog Box Function

Next, you may recall that in the view you set the column list items to be of type

navigation, which would call onMonsterSelected when a user selected a given

row. This is what controllers are all abou t; this function is called from one view

and then goes about linking another view (the dialog box) with the model. Now,

it’s time to code that function using the code in Listing 13.19.

At the start of the code, you check if the dialog box is undefined (i.e., this is the

first time anyone has clicked on a monster). If so, then the fragment is loaded so

that you know what the dialog box has to look like.

610

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!