Skip to Content
author's profile photo Former Member
Former Member

Making use of Formatter.status in SAPUI5

Hello Experts,

I am having trouble figuring out how to pass and recall values in formatter.status from the formatter.js file in the xml view, and vice versa.

My oData service has two fields VarPer and Kflag.

Kflag has values either 1, 2 or 3 for all the records in the field VarPer.

I wish to assign status to VarPer in my xml view as per this logic-

status "Success" for Kflag = 1.

status "Warning" for Kflag = 2.

status "Error" for Kflag = 3.


How do I achieve this?

Thank you in advance,

-Nimish Kate

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 01, 2015 at 06:48 AM

    Thanks to Dennis Seah's solution, I figured out the solution.

    My xml view contains-

    <firstStatus>

    <ObjectStatus

    text="{ValPer}" state="{path: 'Kflag', formatter: 'sap.ui.demo.tdg.util.Formatter.status'}" />

    </firstStatus>

    And my formatter.js contains-

    status : function (sKflag){

    if(sKflag == 1) {

    return "Success";

    }

    else if (sKflag == 2) {

    return "Warning";

    }

    else if (sKflag == 3) {

    return "Error";

    }

    else

    {

    return "None";

    }

    },

    Thanks Dennis Seah for helping me get this!

    Cheers,

    -NK

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 30, 2015 at 07:20 AM

    In view,

    <Text text="{path:'odata>Kflag ',formatter: 'NameSpace.util.Formatter.status'}"/>

    In controller,

    status : function (sts){

    var stsVal;

    if(sts === "1")

    {

    stsVal = "Success";

    }

    if(sts ==="2")

    {

    stsVal = "Warning";

    }

    if(sts ==="3")

    {

    stsVal ="Error";

    }

    return stsVal;

    },

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.