cancel
Showing results for 
Search instead for 
Did you mean: 

Colored Table Cells

Former Member
0 Kudos

Hi all,

I want to display my table cells in different colors based on the value I get from my BAPI.I have just one column in the table which I m trying to set colors. The model attribute is returning values RED,GREEN and GREY.

My view context:

Z_BAPI_M

---Output

-


Material_View_Res (Model Node)

-


Accounting(model attribute)

cellcolor(value node)

-


cellDesign1(value attribute)

int nodeSize = wdContext.nodeMaterial_View_Res().size();

IPrivateTitleMaintenanceView.IMaterial_View_ResNode materialViewRes =

wdContext.nodeMaterial_View_Res();

IPrivateTitleMaintenanceView

.IMaterial_View_ResElement materialViewResElement;

for (int i = 0; i < nodeSize; i++) {

wdComponentAPI.getMessageManager().reportSuccess(

"inside loop " + i);

Zmmweb_St_Material_View materialView =

new Zmmweb_St_Material_View();

materialViewResElement =

materialViewRes.createMaterial_View_ResElement(materialView);

materialViewRes.addElement(materialViewResElement);

wdComponentAPI.getMessageManager().reportSuccess(

"create element and add " + i);

String strStatus =

wdContext.nodeMaterial_View_Res().getElementAt(

i).getAttributeAsText(

"Accounting");

wdComponentAPI.getMessageManager().reportSuccess(

"Accounting " + strStatus);

// if (strStatus.equalsIgnoreCase("GREY")) {

// wdComponentAPI.getMessageManager().reportSuccess(

// "Accounting color inside first if condition" + strStatus);

// wdContext.currentContextElement().setCellDesign1(WDTableCellDesign.STANDARD);

// }

if (strStatus.equalsIgnoreCase("RED")) {

wdComponentAPI.getMessageManager().reportSuccess(

"Accounting color inside second if condition" + strStatus);

IPrivateTitleMaintenanceView.ICellcolorElement cellColorElement = wdContext.nodeCellcolor().createCellcolorElement();

IPrivateTitleMaintenanceView.ICellcolorNode cellColorNode = wdContext.nodeCellcolor();

cellColorNode.addElement(cellColorElement);

cellColorElement.setCellDesign1(WDTableCellDesign.NEGATIVE);

// wdContext.nodeCellcolor().getElementAt(i);

wdComponentAPI.getMessageManager().reportSuccess(

"get each cellcolor element");

//wdContext.current

}

}

The problem is I am not able to set each cell based on the values from backend. Its getting set either Red or Grey or Green.

Please tell me where I went wrong?

Thanks

Anjana

Accepted Solutions (1)

Accepted Solutions (1)

former_member197348
Active Contributor
0 Kudos

Hi Anjana,

You have to create a context attribute of com.sap.ide.webdynpro.uielementdefinitions.TextViewSemanticColor with properties <b>calculated</b> and <b>read only</b> true.Set the WDTableCellDesign property of the table to In the getattribute method return values of type TextViewSemanticColor .X (positive for green, negative for Red and exactly Grey iss not possible some other colour need to be set) depending on condition(strStatus.equalsIgnoreCase("X"))

regards,

Siva

Former Member
0 Kudos

Hi Siva,

I have made my context value attribute cellDesign1 to com.sap.ide.webdynpro.uielementdefinitions.TextViewSemanticColor .set calculated to true. If i set read only to true, I wont be able to set the value.So I left it false.

The second line in ur post is not clear. What should I set the wdtablecelldesign property to. I have set it to cellDesign1. and based on the condition I am setting

cellColorElement.setCellDesign1(WDTextViewSemanticColor.NEGATIVE);//for Red

But its not giving any colors now.

Am I missing something?

Thanks

Anjana.

former_member197348
Active Contributor
0 Kudos

Sorry,

I just missed something. I make it clear here. Set read only true. Since this is a calculated attribute a method getcellDesign1() of return type TextViewSemanticColor is created. In this method write th following

if (strStatus.equalsIgnoreCase("RED")) {

return WDTextViewSemanticColor.NEGATIVE;

}

else if (strStatus.equalsIgnoreCase("GREEN")) {

return WDTextViewSemanticColor.POSITIVE;

}

else

return WDTextViewSemanticColor.STANDARD;

Set this context attribute cellDesign1 to semanticColor property of your textView in the table

Regards,

Siva

Former Member
0 Kudos

Hi Siva,

In my View init() I am calling my BAPI.

my context :

cellColor(value node)

---cellDesign1(value attribute)

Now I have made the cell design1 to com.sap.ide.webdynpro.uielementdefinitions.TextViewSemanticColor.

and made my layout textview semanticColor property to cellDesign1.

I got the new method getcellColorDesign1(IPrivateTitleMaintenanceView.ICellcolorElement element){

int nodeSize = wdContext.nodeMaterial_View_Res().size();

IPrivateTitleMaintenanceView.IMaterial_View_ResNode materialViewRes =

wdContext.nodeMaterial_View_Res();

IPrivateTitleMaintenanceView

.IMaterial_View_ResElement materialViewResElement;

for (int i = 0; i < nodeSize; i++) {

String strStatus =

wdContext.nodeMaterial_View_Res().getElementAt(

i).getAttributeAsText(

"Accounting");

if (strStatus.equalsIgnoreCase("RED")) {

return WDTextViewSemanticColor.NEGATIVE;

} else if (strStatus.equalsIgnoreCase("GREEN")) {

return WDTextViewSemanticColor.POSITIVE;

} else

return WDTextViewSemanticColor.STANDARD;

}

return null;

}

I am not getting the color set in my cell.Where did I went wrong?Is my loop correct?

Thanks

Anjana

former_member197348
Active Contributor
0 Kudos

Hi Anjana,

Put cellcolor node in Material_View_Res node

cellcolor node properties <i>singleton false</i> cardinality 1..1

//try with current element if not possible then use get ith element

String strStatus =

wdContext.nodeMaterial_View_Res().currentMaterial_View_ResElement(

i).getAttributeAsText(

"Accounting");

if (strStatus.equalsIgnoreCase("RED")) {

return WDTextViewSemanticColor.NEGATIVE;

} else if (strStatus.equalsIgnoreCase("GREEN")) {

return WDTextViewSemanticColor.POSITIVE;

} else

return WDTextViewSemanticColor.STANDARD;

}

Just remove <b>return null</b>; in last line

regards,

Siva

Former Member
0 Kudos

Hi,

This feature of coloured tabled cells are supported from<b> 2004s</b> onwards, Which version are you using.

Regards

Ayyapparaj

Former Member
0 Kudos

Hi ,

Thanks for all your responses.

I am using NW2004s and followed the same method as in the blog for "Colored Table". Its working now.

Thanks

Anjana.

Answers (1)

Answers (1)

raja_thangamani
Active Contributor
0 Kudos

Edited

Message was edited by:

Raja Thangamani