5

I have Fiori applications using fiori element and I want to tweak the odata queries that UI5 generated for OData in $batch calls.

I have livemode turned for the list report along with smartfilter for selection/filter and list of values using ValueList annotations. But the problem is when I type in the filter value in selection fields (lets say for sold to) the $batch call fires the below query for OData.

../invoice_list.xsodata/vlsoldto?sap-client=100&$skip=0&$top=10&$filter=startswith(SOLDTO___T,%27TEST%27)

I want to tweak the the odata call to use 'substringof' instead of 'startswith'.. so something like below.

../invoice_list.xsodata/vlsoldto?sap-client=100&$skip=0&$top=10&$filter=substringof(%27TEST%27,CRM_SOLDTO___T)

I don't know the spot where I can do this customization. I know how to do Fiori elements extensions, but looking for some info if its an extension then which type of extension, which event, or any other approach if not extension. I have very little idea on where to start.

Any help is appreciated.

Jon
  • 3,573
  • 2
  • 17
  • 24
05_pingpong
  • 77
  • 1
  • 2
  • 13
  • I suppose zou talk about the Combobox ? See 'Filtering the Option list' here: https://experience.sap.com/fiori-design-web/combo-box/#filtering-the-option-list – Lumpenstein Aug 19 '19 at 09:43
  • Mine is a multiInput. But when I add setFilterFunction as below, it doesn't change filter to contains (rather than startsWith) **************************************************************************** oMultiInput.setFilterFunction(function(sTerm, oItem) { // A case-insensitive 'string contains' filter return oItem.getText().match(new RegExp(sTerm, "i")); }); – 05_pingpong Aug 19 '19 at 10:45

1 Answers1

0

You can add your own fields in the SmartFilterBar and then create your own custom filter:

https://sapui5.hana.ondemand.com/#/topic/3a515829ffd74239878ebc0d453d001d

Edit: if you want to use the existing fields you can just push a new filter with sap.ui.model.FilterOperator.Contains on the beforeRebindTable event.

Step 1: Register your extension in your manifest.json file

"extends": {
   "extensions": {
      ... 
      "sap.ui.controllerExtensions": { 
         ...
         "sap.suite.ui.generic.template.ListReport.view.Details": { 
            ... 
            "controllerName": "com.acme.app.controller.ListReportExtension",
            ...
         }
      } 
      ...

Step 2: implement the controller method:

sap.ui.controller("com.acme.app.controller.ListReportExtension", {
        onBeforeRebindTableExtension: function(oEvent) {
        var oBindingParams = oEvent.getParameter("bindingParams");
        oBindingParams.parameters = oBindingParams.parameters || {};

        var oSmartTable = oEvent.getSource();
        var oSmartFilterBar = this.byId(oSmartTable.getSmartFilterId());
        var vCategory;
        if (oSmartFilterBar instanceof sap.ui.comp.smartfilterbar.SmartFilterBar) {
            //Custom price filter
            var oCustomControl = oSmartFilterBar.getControlByKey("CustomPriceFilter");
            if (oCustomControl instanceof sap.m.ComboBox) {
                vCategory = oCustomControl.getSelectedKey();
                switch (vCategory) {
                    case "0":
                        oBindingParams.filters.push(new sap.ui.model.Filter("Price", "LE", "100"));
                        break;
                    case "1":
                        oBindingParams.filters.push(new sap.ui.model.Filter("Price", "GT", "100"));
                        break;
                    default:
                        break;
                }
            }
        }
    }
});
fvdalcin
  • 1,047
  • 1
  • 8
  • 26