cancel
Showing results for 
Search instead for 
Did you mean: 

OData filtering a filtered table

Former Member
0 Kudos

Hi,

maybe someone can help me a little bit.

I'm filtering an OData-Servive and fill a table with the filtered results by the following controller-function:

setTable: function ($this, $view, sCustomer, sVersion, sHierid, sFiscalYear) {

     var sServiceURI = "/sap/opu/odata/xxx/A_0003_SRV";

     var oModel = new ODataModel(sServiceURI, true);

     $view.setModel(oModel, "oA0003Model");

     var oDataFilters = [];

     var oTblData = $view.byId("idTableD");

     var oBindingData = oTblData.getBinding("items");

     oDataFilters.push(new Filter('ApplicationPa', FilterOperator.EQ, 'A'));

     oDataFilters.push(new Filter('CustomerPa', FilterOperator.EQ, sCustomer));

     oDataFilters.push(new Filter('VersionPa', FilterOperator.EQ, sVersion));

     oDataFilters.push(new Filter('HieridPa', FilterOperator.EQ, sHierid));

     oDataFilters.push(new Filter('FiscalYearPa', FilterOperator.EQ, sFiscalYear));

     oBindingData.filter(oDataFilters);

     .......

}

Up to this point, it works fine.

Now I want to be able, to filter this table (with columns: "Unitid | Unitname | Value1 | Value2") again by a standard SeachField placed in a xml-view.

How can I do this ? Because for me, it seems that this would be a filter of a filter ?

Best regards

Achim

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

OK, I found one possibilty. I defined the following controller-function:

filterSearchField: function(oEvent) {

     var sQuery = oEvent.getParameter("query");

     var oDataFilters = [];

     var oTblData = $view.byId("idTableD");

     var oBindingData = oTblData.getBinding("items");

     oDataFilters.push(new Filter('ApplicationPa', FilterOperator.EQ, 'A'));

     oDataFilters.push(new Filter('CustomerPa', FilterOperator.EQ, sCustomer));

     oDataFilters.push(new Filter('VersionPa', FilterOperator.EQ, sVersion));

     oDataFilters.push(new Filter('HieridPa', FilterOperator.EQ, sHierid));

     oDataFilters.push(new Filter('FiscalYearPa', FilterOperator.EQ, sFiscalYear));

     if (sQuery) {

          oDataFilters.push(new Filter('Unitname', FilterOperator.EQ, sQuery));

     }

     oBindingData.filter(oDataFilters);

}

This code above is function well, but if I change the FilterOperator of snipped

     oDataFilters.push(new Filter('Unitname', FilterOperator.EQ, sQuery));

from EQ to Contains, than there occurs always a RFC-Error: Failure by parsing the dynamic WHERE-Clause.

Is there somebody with any idea ?

Thanks & best regards

Achim

ugurkaya
Active Participant
0 Kudos

Hey Achim,

Filter parameters should be handled differently according to the operator used. Could you debug the related entityset get method to see the requested filter select options and how it is handled on the backend.

Former Member
0 Kudos

Hi Ugur,

many thanks for your answer.

The backend-programmer solved this.

Now I use it with FilterOperator Contains.

But if I want to use it with e.g. three Contains like this:

oDataFilters.push(new Filter([

    new Filter('ApplicationPa', FilterOperator.EQ, 'A'),

    new Filter('CustomerPa', FilterOperator.EQ, sCustomer),

    new Filter('VersionPa', FilterOperator.EQ, sVersion),

    new Filter('HieridPa', FilterOperator.EQ, sHierid),

    new Filter('FiscalYearPa', FilterOperator.EQ, sFiscalYear),

    new Filter([

        new Filter('StatusId', FilterOperator.Contains, sQuery),

        new Filter('Unitid', FilterOperator.Contains, sQuery),

        new Filter('Unitname', FilterOperator.Contains, sQuery)

        ], false)

], true));

So that the filter should be like

(ApplicationPa==x && CustomerPa==y && VersionPa==z && HieridPa==aa && FiscalYearPa==bb && (StatusId==sQuery  ||  Unitid==sQuery  ||  Unitname==sQuery))

Than I will get a 400 Bad-Request-Error.

How should I construct the filter, for the logic, which I describt above ?

regards

Achim

ugurkaya
Active Participant
0 Kudos

Hey Achim,

Once i had a requirement like that, as I remember I handled this situation again on backend side. What I did was sending one filter instead of 3 filters with OR logic.

For example: On the backend if there is a filter for StatusId, I understand that  I need to add filter to all 3 fields (statusid, unitid, unitname ) and adjust my search parameters on the backend query. That could be an alternative if those three fields can only be filtered together, not seperately.

That may not be the best way to approach your case, I am also curious about using OR logic like that. Lets see if we can find anything for this.

Former Member
0 Kudos

Hi Ugur,

after discussion with the backend-programmer, we decided to solve this with one SearchFilter for each Column and using only AND-Operators.

Because for a nested filter including ANDs and ORs, we couldn't found a solution.

So many thanks & regards

Achim

Answers (0)