on 06-30-2015 8:05 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.