Search code examples
javascripterror-handlingsapui5highlightformatter

SAPUI5 formatter function not found


I know this question has been asked before here but the answer didn't help me.

This is my controller code:

 sap.ui.define([
        // there's more stuff importet here    
       'project/util/formatter',
    ], function (formatter ) {
       'use strict';
    return BaseController.extend('project.controller.ManualUpload', {

        formatter:formatter,

        onShowErrors: function() {
          //some other stuff happening here

        _.forEach(checkValidations, entry => {
            var errorMessage = oData[entry].ERROR_MSG;
            if(errorMessage) {
                var rowSettingsTemplate = new sap.ui.table.RowSettings({ highlight: "{ path: 'odataDetails>ERROR_MSG', formatter: '.formatter.errorStatus' }" }); 
                backendTable.setRowSettingsTemplate(rowSettingsTemplate);
            }
        });
       },
    });  
});

And this is my formatter with the function errorStatus()

sap.ui.define(function() {
    'use strict';
    return {
            errorStatus: function(errorMessage) {
            if (_.isEmpty(errorMessage)) {
                return 'None';
            } else {
                return 'Error';
            }    
        },    
    };
});

The formatter is found so this can't be the problem. Also I declared the formatter in the beginning of my controller, so that should be fine, too. Another suggested solution was the function call without parenthesis. I don't do this, so that can't be the problem either.

The error message is:

formatter function .formatter.errorStatus not found


Solution

  • I think the way you have attempted the binding is wrong.

    In js view, you can bind as follows:

    var rowSettingsTemplate = new sap.ui.table.RowSettings({
    
      highlight: {
        path: "odataDetails>ERROR_MSG",
        formatter: formatter.errorStatus
      }
    });

    Hope this helps.