17

Intercept Go (Start)-Button in Fiori Elements List Report Template (OData V4)

 1 year ago
source link: https://answers.sap.com/questions/13820797/intercept-go-start-button-in-fiori-elements-list-r.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Feb 14 at 05:23 PM

Intercept Go (Start)-Button in Fiori Elements List Report Template (OData V4)

101 Views

Hi Community,

I'm working as Fiori/UI5 Developer for Stadtwerke München (SWM) - the local Utilities Company in Munich.

I've got an urgent Requirement from our End-Users:

In one of our Fiori Elements List Reports (OData V4), there are 2 filter fields on the filter bar.

At least one of these 2 fields must be filled with a value (provided by the End-User). It's ok if both are filled, but it's not ok, if none is filled.

In this case we need to generate an error message and prevent the framework from calling the OData Service for reading the data.

We cannot simply set both fields to mandatory, because it must be possible to fill just one field.

And simply attaching an event handler to the Go-Button doesn't do the trick, either, because the service-call (read) is triggered beforehand.

So, it would be great to have a hook (e.g. via controller extension) in order to intercept the read trigger after pushing the Go (Start)-Button or the Enter Button with focus on a filter field.

I saw, that there are a couple of framework hooks in Edit mode - but none in read mode :-(

Does anyone had a similar problem and found a solution for it?

Any kind of help is more than welcomed :-)

I think Durga Prasanth had a similar question:

validation-on-go-button-in-fiori-element-list-report

Unfortunately, the answer didn't solve our problem.

Regards

Thorsten Klingbeil

3 comments
Feb 14, 2023 at 08:14 PM

Hi Thorsten,

would it be an option to solve this in the backend?

CU
Gregor

13 hours ago

Hi Thorsten Klingbeil,

Did you get any solution, we have similar kind of requirement.

Please let me know, if you are done with it.

Thanks,

Preethi Ande

1 minute ago

Hi Preethi,

we finally solved it in the backend (Validation and Error Message in the OData-Service).

However, I found this article in the UI5 docs: Extension Points for Views in the List Report

There are two hooks mentioned which can be overridden in a Controller Extension (onViewNeedsRefresh / on PendingFilters):

sap.ui.define(["sap/ui/core/mvc/ControllerExtension", "sap/ui/model/Filter"], function(ControllerExtension, Filter) {
    "use strict";
    return ControllerExtension.extend("BusinessPartners.custom.LRExtend", {
        override: {
            onViewNeedsRefresh: function(mParameters) {
                var oFilterInfo = mParameters.filterConditions;
                if (oFilterInfo) {
                    var duplicateFilterInfo = Object.assign({}, oFilterInfo);
                    if (
                        duplicateFilterInfo.Region &&
                        duplicateFilterInfo.Region.map(item => item.values).findIndex(i => i.includes("Bavaria")) !== -1
                    ) {
                        delete duplicateFilterInfo.Region;
                    }
                    var oTable = this.getView().byId("BusinessPartners::BusinessPartnersList--fe::CustomTab::tab2--customViewWithTable"),
                        oBinding = oTable.getBinding("items"),
                        oConvertedFilter = this.base.getExtensionAPI().createFiltersFromFilterConditions(duplicateFilterInfo);
                    oTable.setShowOverlay(false);
                    var oFilter = new Filter({ filters: oConvertedFilter.filters, and: true });
                    oBinding.filter(oFilter);
                    oBinding.changeParameters({$search: oConvertedFilter.search});
                }
            },
            onPendingFilters: function() {
                var oTable = this.getView().byId("BusinessPartners::BusinessPartnersList--fe::CustomTab::tab2--customViewWithTable");
                if (oTable) {
                    oTable.setShowOverlay(true);
                }
            }
        }
    });
});

Maybe this helps ...

Thorsten


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK