cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Passing Filter parameter in bindElement of view

0 Kudos
6,115

Hello Folks,

I am trying to pass filters in bindElement method of a view as shown in blow code. This does not work. And also, in the parameters, it accepts only expand and select. Could you please let me know how to pass the filters.

this.getView().bindElement({

path: sObjectPath,

parameters: {

expand: sExpand

},

filters: [new sap.ui.model.Filter(sFieldName, "EQ", sValue)],

events: {

change: this._onBindingChange.bind(this),

dataRequested: function() { },

dataReceived: function(oData) { }

} });

Best Regards

Srini

Accepted Solutions (0)

Answers (2)

Answers (2)

kammaje_cis
SAP Mentor
SAP Mentor

By Looking into the documentation, it looks like $filter is supported only with OData V4 model.

For V2, I would suggest trying to put it in the URL itself. (path)

WouterLemaire
SAP Mentor
SAP Mentor
0 Kudos

bindElement is used for binding one entry of an entity using the keys for that entity. This should always return only one record! 

if you want to use filtering on a list you have to use binding aggregation as described here: https://sapui5.hana.ondemand.com/sdk/#/topic/ec79a5d5918f4f7f9cbc2150e66778cc

 

LiyaAjayan
Explorer
0 Kudos

Thank you. I have to return only one record, but when I call the service I have to pass a non-key field as a filter along with key fields. I am able to pass the key fields with createKey method.

Could you please guide if we can pass non key field to the get entity method?

WouterLemaire
SAP Mentor
SAP Mentor
0 Kudos
One option would be to make this field part of the key, another would be to use a header parameter: https://community.sap.com/t5/technology-blogs-by-sap/set-and-get-custom-http-header/ba-p/13222035
LiyaAjayan
Explorer
0 Kudos

Thank you. I couldn't make it as key field since the condition is not EQ and is taking values directly from CDS (BSP app) and impacts other functionality.

I will try the option with header parameters.