简体   繁体   中英

Filtered the Odata service value for date range with and:false condition SAPUI5

enter image description here i would like to implement sap.ui.model.Filter which have new sap.ui.model.Filter(sPath, sap.ui.model.FilterOperator.BT, vValue1, vValue2); like this i have 8 field i am filtering like this only but for 2 field i need to implement the and:False condition.

https://sapui5.hana.ondemand.com/#/api/sap.ui.model.Filter

 var product = comboBoxValue.products; product.forEach(function (allproduct) { allproduct = allproduct.toUpperCase(); var productValue1 = new sap.ui.model.Filter("PRODUCT", sap.ui.model.FilterOperator.Contains, allproduct); filters.push(productValue1); }); // filter the Country values var country = comboBoxValue.locations; country.forEach(function (allcountry) { // allcountry = allcountry.toUpperCase(); var countryValue = new sap.ui.model.Filter("COUNTRY", sap.ui.model.FilterOperator.Contains, allcountry); // filters.push(countryValue); }); // filter the Status value var status = comboBoxValue.status1; status.forEach(function (allstatus) { // allcountry = allcountry.toUpperCase(); var statusValue = new sap.ui.model.Filter("SUB_STATUS1", sap.ui.model.FilterOperator.Contains, allstatus); filters.push(statusValue); }); // filter the Change type values var change_type = comboBoxValue.changes; change_type.forEach(function (allchanges) { // allcountry = allcountry.toUpperCase(); var changeValue = new sap.ui.model.Filter("CHANGE_TYPE", sap.ui.model.FilterOperator.Contains, allchanges); filters.push(changeValue); }); // filter the Submission type values var sub_type = comboBoxValue.Submissions1; sub_type.forEach(function (allsub) { allsub = allsub.toUpperCase(); subValue = new sap.ui.model.Filter("SUB_TYPE", sap.ui.model.FilterOperator.Contains, allsub); filters.push(subValue); }); // filter the Manufacturing Stage var manu_stage = comboBoxValue.stages1; manu_stage.forEach(function (allstage) { allstage = allstage.toUpperCase(); var stageValue = new sap.ui.model.Filter("MANUFACTURING_STAGE", sap.ui.model.FilterOperator.Contains, allstage); filters.push(stageValue); });

filters is array i am passing to oData service like

 oModel6.read("/gantt", { filters: filters, success: function (oData, oResponse) { // checking if its region Gantt Chart view console.log("filtered data will come in oData "); } error: function(e){ } });

now i have give six filters.push(productValue1); passing the after var productValue1 = new sap.ui.model.Filter("PRODUCT", sap.ui.model.FilterOperator.Contains, allproduct); filtering it using the Sapui5 control filter. to array filters. Now i want 2 more filter for date range as

 for (var g = 0; g < comboBoxValue.date_type.length; g++) { var range = new sap.ui.model.Filter(comboBoxValue.date_type[g], sap.ui.model.FilterOperator.BT, sFrom, sTo); oFilter.push(range); }

in this i am passing the multiple comboBoxValue.date_type values and start date, end date for it
For other filter its standard sapui5 taking and:true (you refer https://sapui5.hana.ondemand.com/#/api/sap.ui.model.Filter this link)

but for this particular filter i need to give and:false and give this and:false to my filter array called filters

final statement: total 8 value where 6 are normal stadard filter with and:true and storing in filters array and 2 more field date range with dat_type want and:false and store this in filters array

In Image 2 values are i want in and:false and other in and:true

As I understand your issue, you have a total of 8 condition for which you want 6 of them to be concatenated with an "or" and two of them with an "and". This behaviour is explained in the docs with sample #3.

new Filter({
filters: [
  ...
  new Filter({
    path: 'Quantity',
    operator: FilterOperator.LT,
    value1: 20
  }),
  new Filter({
    path: 'Price',
    operator: FilterOperator.GT,
    value1: 14.0
  })
  ...
],
and: true|false

})

This shows you that you can nest filters in filters, which would be the way for you to solve your issue. In your case you would need three layers of nesting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM