sap ui5 filter with $expand

3
Generated by Jive on 2015-12-15+01:00 1 ODataModel.read: pass select and filters  Oliver Ester 3 posts since Mar 18, 2015 ODataModel.read: pass select and filters  Jun 27, 2015 1:10 PM Hi!  How is it possible to pass a select parameter and filters to the ODataModel.read function?  I found this example in the SAP help:  oModel.read('/Products(1)', null, null, true, function(oData, oResponse){  alert("Read success ful: " + JSON.stringify(oData));  },function(){ alert("Read failed");});  However isn't it contracdicting to the API?: JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel  Thanks for your help! Oliver Tags: parameter, odata, select, read, filters  Sarath Chandra 148 posts since Oct 1, 2009 Re: ODataModel.read: pass select and filters  Jun 27, 2015 2:52 PM  // Creating a filter object so preparing arrays for Ids and Values separately. aFilterIds = ["sProductId"]; aFilterValues = [sProductIdValue];   // once the Id and Values are prepared separately, dynamicall y prepare the filter object by calling below method. aFilters = this._createSearchFilterObject(aFilterIds, aFilterValues);   //Build the Parameters required for the Read met hod. var mParameters = {  filters : aFilters,  urlParameters:{"$select" : "Category,ProductName", "$expand" : "Category" }  success : function (oData) {

Upload: ramana-yellapu

Post on 18-Feb-2018

370 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SAP UI5 Filter With $Expand

7/23/2019 SAP UI5 Filter With $Expand

http://slidepdf.com/reader/full/sap-ui5-filter-with-expand 1/3

Generated by Jive on 2015-12-15+01:00

1

ODataModel.read: pass select and filters

 Oliver Ester 3 posts since Mar 18, 2015

ODataModel.read: pass select and filters Jun 27, 2015 1:10 PM

Hi!

 

How is it possible to pass a select parameter and filters to the ODataModel.read function?

 

I found this example in the SAP help:

 

oModel.read('/Products(1)', null, null, true, function(oData, oResponse){

  alert("Read successful: " + JSON.stringify(oData));

  },function(){

alert("Read failed");});

 

However isn't it contracdicting to the API?:

JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.odata.ODataModel

 

Thanks for your help!

Oliver

Tags: parameter, odata, select, read, filters

 Sarath Chandra 148 posts since Oct 1, 2009 

Re: ODataModel.read: pass select and filters Jun 27, 2015 2:52 PM

 // Creating a filter object so preparing arrays for Ids and Values separately.

aFilterIds = ["sProductId"];

aFilterValues = [sProductIdValue];

 

 // once the Id and Values are prepared separately, dynamically prepare the filter object by calling below

method.

aFilters = this._createSearchFilterObject(aFilterIds, aFilterValues);

 

 //Build the Parameters required for the Read method.

var mParameters = {

  filters : aFilters,

  urlParameters:{"$select" : "Category,ProductName", "$expand" : "Category" }

  success : function (oData) {

Page 2: SAP UI5 Filter With $Expand

7/23/2019 SAP UI5 Filter With $Expand

http://slidepdf.com/reader/full/sap-ui5-filter-with-expand 2/3

ODataModel.read: pass select and filters

Generated by Jive on 2015-12-15+01:00

2

  jQuery.sap.log.info("Odata Read Successfully:::");

  }.bind(this),

  error: function (oError) {

  jQuery.sap.log.info("Odata Error occured");

  }.bind(this)

  }; 

 // As the parameters is build, start calling read method with sPath and mParameters.

  if (oModel) {

  oModel.read(sPath, mParameters);

  }

 

 // method to create different filters.(modify according to ur requirement.)

  /**

  * Assign the filter objects based on the input selection

  *

  * @function

  * @param {Array} aFilterIds to be used as sPath for Filters

  * @param {Array} aFilterValues for each sPath

  * @private

  */ 

  Controller.prototype._createSearchFilterObject = function (aFilterIds, aFilterValues) {

  var aFilters = [],  iCount;

 

for (iCount = 0; iCount < aFilterIds.length; iCount = iCount + 1) {

  aFilters.push(new Filter(aFilterIds[iCount], FilterOperator.EQ, aFilterValues[iCount], ""));

  }

  return aFilters;

  };

 

Hope this helps.

 

Thanks.

Sarath.

 Oliver Ester 3 posts since Mar 18, 2015 

Page 3: SAP UI5 Filter With $Expand

7/23/2019 SAP UI5 Filter With $Expand

http://slidepdf.com/reader/full/sap-ui5-filter-with-expand 3/3

ODataModel.read: pass select and filters

Generated by Jive on 2015-12-15+01:00

3

Re: ODataModel.read: pass select and filters Jun 27, 2015 3:44 PM

Perfect, thanks for your help!

 indrajith patel 351 posts since Nov 10, 2014 

Re: ODataModel.read: pass select and filters Jun 27, 2015 3:33 PMMaybe this helps.

Filter Support for (sap.ui.model.odata.ODataModel).read(...) Function