cancel
Showing results for 
Search instead for 
Did you mean: 

Making use of Formatter.status in SAPUI5

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (1)

Answers (1)

santhu_gowdaz
Active Contributor
0 Kudos

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;

        },

Former Member
0 Kudos

Hi Santhosh,

Thanks for the quick reply.

Your solution works, just slightly in a wrong way.

I didnt intend to print "Success", "Warning" and "Error" in the view.

I have data in my odata service in the field VarPer. What i want is the status "Success", which makes the data in the field VarPer green in the output.

Can you help me out in this context?

Thanks,

-NK

santhu_gowdaz
Active Contributor
0 Kudos

k fine using formatter change the color.

In formatter.js,

statusColor : function (sts){

            var stsVal;

             if(sts === "Success")

               {

                stsVal = "#090";

               }

               if(sts ==="Warning")

               {

                stsVal = "#c00";

               }

               if(sts ==="error")

               {

                stsVal = "#f60";

               }

            return stsVal;

        },

Former Member
0 Kudos

Hi Santhosh,

It is still not working.

I want to use the status function of the library, where when you return "Success", the color of the said text automatically turns green. I can work this logic out on hardcoding the values for VarPer.

My view.xml code-

<firstStatus>

  <ObjectStatus

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

</firstStatus>

My formatter.js code-

status : function (sValPer){

             if(sValPer === "1")

               {

                return "Success";

               }

               if(sValPer === "2")

               {

                return "Warning";

               }

               if(sValPer === "3")

               {

                return = "Error";

               }

        }

This works just fine for me. What i want is to use the field Kflag from my odata service for this status assignment. Instead of checking like I have, Kflag should be checked as 1, 2 or 3; and based on that, the value of ValPer should get assigned the status "Success", "Warning" or "Error" respectively.

Something like if Kflag is 1, return "Success" to ValPer (which will make the values in ValPer green).

How do I achieve this logic?

Thanks,

-NK

former_member182862
Active Contributor
0 Kudos

Then it should be like this

  

<firstStatus>

  <ObjectStatus

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

</firstStatus>

My formatter.js status : function (v){     if(v === "1") {         return sap.ui.core.ValueState.Success;     }     if (v === "2") {         return sap.ui.core.ValueState.Warning;     }     if (v === "3") {         return sap.ui.core.ValueState.Error;     }     return sap.ui.core.ValueState.None; }

Thanks

-D

Former Member
0 Kudos

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