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 comment
10|10000 characters needed characters exceeded

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 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 comment
    10|10000 characters needed characters exceeded

    • Former Member Dennis Seah

      Hi Dennis,

      No, sadly it doesnt work. The return path is Kflag and the field to be displayed is VarPer.

      Tried your suggestion, the field disappeared :/

      Anything else would be welcome.

      Thanks,

      -NK