cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically change cell properties in a table

Former Member
0 Kudos

Hi,

I have read all forum posts about changing table cell properties, but I can't find the solution to my problem.

I have a table that derives its structure from a table which is the output of an RFC.

The rows are provided by the model.

When displaying the result of the RFC call, I want to add a colored row between certain sections with totals of that particular section.

I managed to add the row in the appropriate place, however I cannot change the color of this row (or even better: the particular cell).

Can anyone tell me how to proceed? And what property determines backgroundcolor of a tablecell? TextViewSemanticColor determines the text color, I want to change the background color.

Here is a fragment from my wdDoModifyView:

i=0;

IPrivateResultView.IEp_OpportunitiesNode node = wdContext.nodeEp_Opportunities();

while (i<node.size()) {

total1 += <some value>;

total2 += <some value>;

if (<start of new section>) {

IPrivateResultView.IEp_OpportunitiesElement el = (IPrivateResultView.IEp_OpportunitiesElement) node.createElement(new Zopportunities());

el.setAttributeValue("Exp_Revenue", new BigDecimal(total1));

el.setAttributeValue("Chancevalue", new BigDecimal(total2));

// totals row is added here:

node.addElement(i, el);

// how can I make this work for background color?

el.node().getNodeInfo().addAttribute("TextViewSemanticColor", "ddic:com.sap.ide.webdynpro.uielementdefinitions.TextViewSemanticColor");

el.setAttributeValue("TextViewSemanticColor", WDTextViewSemanticColor.NEGATIVE);

total1 = 0;

total2 = 0;

}

i++;

}

Thanks in advance,

Roelof

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks.

I've tried several things, but no result.

Is there a more elaborate guide for doing this?

Some of the things I don't understand:

If I use a boolean attribute (<b>Bala's approach</b>):

- What should the attribute be called?

- How do I 'play' with the readonly property of the cell attribute? (I am not using input fields inside the table)

- How can I give the table cell or line a blue or yellow background?

If I create a TextViewSemanticColor attribute (<b>Valery's approach</b>):

- Should the attribute be of type TextViewSemanticColor and also have this name? If not, what constants do I return or what name do I provide?

- Where can I set flags that can be read from the element parameter?

- What am I doing wrong: when I leave the 'setAttribute' statement, it produces a nullpointerror, when I omit it I get a ContextException saying the attribute is unknown. (Note that the element being added -a tablerow- is derived from the model class, whereas I added the attribute to the view context.)

Thanks for anyone that can help me further.

Roelof

Former Member
0 Kudos

Hello Knibbe,

One can play with the readOnly of table cell editor (Input Field) to acheive the expected result.

Let us take a specific case where your table has four columns say col1, col2, col3, col4 and each of these columns have Input field as the table cell editor.

Then depending upon the condition specified below choose your option.

<u>If you have bound the table to the model node</u>

1. Create a new value node and create a bolean value attribute under it.

2. Set the cardinality of the value node to 1:1 and singleton to false.

3. Bind this attribute to the Table cell editor <b>(Inputfield)</b> in col1, col2, col3 and col4.

4. set the value of this attribute to TRUE when the table gets filled up initially i.e for the elements/rows in which you want to display the total, as per your requirement.

5. set the value of this attribute to FALSE for the other rows where you want the user to edit the data.

<u>If you have bound the table to a value node</u>

1. Create a value attribute of type boolean under the value node and follow the ONLY the steps 3, 4 and 5

Please reward appropriate points.

Bala

Message was edited by: Bala Krishnan

Former Member
0 Kudos

Thanks Bala,

I'm slowly getting there.

I can now manipulate the font color and size.

Cell background color however cannot be changed.

TextViewSemanticColor is a supported property.

I'm currently upgrading to SP14 and hope this will support changing cell background color.

Roelof

Former Member
0 Kudos

R. Knibbe,

Functionality you need available only in NW04s (NW 7.0)

No way currently.

VS

Former Member
0 Kudos

Hi Valery,

Thanks for your answer. As you're 'only the messenger' I'll award you the points, but my, how disappointing that the programming model is such a straightjacket that one cannot even change the appearance of a table row or cell at runtime.

It seems that our efforts of the past weeks will be useless as the solution we build for our customer uses colors to represent certain stages.

Isn't there a workaround to this, e.g. create UI elements designtime and swapping them runtime (change visibility?)

Thanks,

Roelof

Former Member
0 Kudos

Roelof,

You post a workaround yourself already -- via TextView semantic color. Sadly, this is the only option in NW04.

<i>create UI elements designtime and swapping them runtime (change visibility?)</i>

It's quite complex. In effect, you have to recreate complete IWDTable control with set of dynamic controls layered either by Matrix or Grid layout.

VS

Former Member
0 Kudos

Knibbe,

Since you've mentioned that you wanted to just display the total in a particular cell/ row, I think you can play with the readonly property of the cell (input field)to acheive the desired result.

If you have bound the table to a value node just add one more attribute of type boolean and bind it to the readonly property and set it to true (readonly) after the required calculations. However, if you have bound your table to a model node, then just add a value node of cardinality 1:1 and singleton -- false and add a boolean attribute and bind it to the readonly property and set it to true.

Bala

Kindly reward appropriate points

Former Member
0 Kudos

Hi Valery, Bala,

QUESTION FOR VALERY:

If it is a workaround, how can I make it work? Or did you mean NW04s, as mentioned in your first posting in this thread? In another posting you suggest to walk the node tree from tail to head. Why?

QUESTION FOR BALA:

I already managed to add a row with totals, I want the appearance of this cell or row to change. Will your suggestion help to do this?

Thanks, Roelof

Former Member
0 Kudos

Hi Knibbe,

Yes. My suggestion will work fine for your requirement.

Please follow the steps I mentioned in my prevoius post, i.e, use a boolean attribute and play with the readonly property of the cell-editor(input field). If you want to grey-out the entire row, then bind all the UI elements in the row to the same attribute.

Bala

Please reward appropriate points

Former Member
0 Kudos

Roelof,

1. Create an attribute of type TextViewSemanticColor (or non-singleton sub-node with cardinality 1..1, selection 1..1 with this attribute). Make attribute calculated. In generated "getter" function return different constants depending on some flag inside supplied "element" parameter (or element.node().parentElement() parameter for sub-node scenario)

2. Common idiom for removing elements of list-like structures is to navigate them from tail to head. This way managing iteration index is much simpler. Works nice with IWDNode.

Sure, this is unnecessary for java.util.List implementations where you can iterate forward with java.util.Iterator and use iterator.remove()

VS