Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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

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

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question