cancel
Showing results for 
Search instead for 
Did you mean: 

Set filter criteria on page 1 for page 2 OData model - "best practice"?

Former Member
0 Kudos

Hello, I have a problem with an app - where I want to filter data on a second page, based on settings from the first page. I use an OData model.

The collections on both pages are not related in terms of "navigation" properties, that is my problem and I can not change the data source...

So I am looking for ideas/best practices to solve this because sometimes my filtering doesn't work... the following problem occurred: Request aborted

I have a page with a sap.m List with items="{/tabWorkPlace}" and and a local JSON model where I store relevant data during the app lifecycle.

handleListSelect - first page


var context = evt.getParameter("listItem").getBindingContext();

var dataModel = sap.ui.getCore().getModel("dataModel");

var workplace = context.getProperty("WORKPLACE_ID");

dataModel.setProperty("/WORKPLACE_ID", workplace);

this.nav.to("SubMaster", context);

The general App.controller.js handles the nav.to function:


var app = this.getView().app;

var page = app.getPage(pageId);

if(pageId == "secondPage") {

     page.getController().filterData();

And the controller of the second page:


filterData: function() {

var oModel = sap.ui.getCore().getModel("odata");

var dataModel = sap.ui.getCore().getModel("dataModel");

var workplace = dataModel.getProperty("/WORKPLACE_ID");

var items = this.getView().byId("list");

var oFilter=new sap.ui.model.Filter("WORKPLACE_ID",sap.ui.model.FilterOperator.EQ,workplace);

items.getBinding("items").filter(oFilter);

I don't write this code into the onInit() or beforeRendering() function, because they are called only once and I am navigating back and forth between the two pages, because the pages are created only once and "just" the data is changed.

The desired page looks like this - with an other collection bound to it:


<List

  id="list"

  select="handleListSelect"

  items="{/tabWorkstep_Status}"

>

But when I call it - then the request gets aborted:

The following problem occurred: Request aborted

But despite the fact the Request is aborted, the list on the second page is filtered!

The filter criteria for the model works when I type it into the browser with URL. Maybe this fails because the data binding for the list didn't took place at this phase?

I have this pattern (filter criteria on one page and result on the second page) more times - (and I think a better data model would be better with navigation properties would be better, but I cannot change it)

But at another constellation the filtering doesn't work - same error... the following problem occurred: Request aborted

I also don't want to change the pattern (page 1 to page 2) into popup lists or this fancy new filtering possibilities because it is not suitable for my use case.

Is there maybe a more elegant solution - because sometimes filtering works, sometimes don't..., do I have an error in my solution (general approach)?

Many thanks for any input!

BR,

Denise

Accepted Solutions (0)

Answers (2)

Answers (2)

qmacro
Developer Advocate
Developer Advocate
0 Kudos

Just a fly-by remark before I launch into my morning's work, but Request Aborted is thrown if, say, the browser changes locations. Are there any unintended occurrences of that?

Former Member
0 Kudos

Hi Denise,


It seems you're using named Models, "odata" , "dataModel". To bind a named model to a list items, you'll have to do namedModel >/Path. Say if you wanna bind the model odata to list, it would be


<List 

  id="list" 

select="handleListSelect" 

  items="{odata>/tabWorkstep_Status}" 

Regards

Sakthivel

Former Member
0 Kudos

Hello, yeah you are right, but it works without the odata> stuff because of this in App.controller.js:


var uri = "http://localhost:32006/JsonOdataService.svc";

var oModelMS = new sap.ui.model.odata.ODataModel(uri);

sap.ui.getCore().setModel(oModelMS, "odata");

oView.setModel(oModelMS);

So my question is - how to navigate from one page to another - and on the other page first bind a collection to a select and then when selecting bind certain elements (a textfield) to the selected filtered entity.

The stuff with context and binding won't work, because the two Collections don't have a navigation/association property between them...

So for example:

page1

select a list item with property color: red and year 1985. Press one of the buttons and pass this criteria to another page.

page 2:

show a dropdown box with all car names which fullfill this criteria, and when one car is selected, then display the data for THIS car in several text fields.

This is not a master->detail navigation example, because on page 1 i select certain criterias, and then with buttons I navigate to several pages with those criterias.

But since the OData model has no relationships it is really hard to do it manually... With a dummy mock.json like in DJ Adams Fiori like SAPUI5 apps it is no problem... But with OData and no things related to each other it is hard...