cancel
Showing results for 
Search instead for 
Did you mean: 

Adding one row to a table for displaying calculated amounts

Former Member
0 Kudos

Hi,

My requirement is like this:

We are getting values in the table with the columns

recno rectype amount

1 autofare 100

2 airfare 50

3 busfare 25

4 railfare 10

5 carfare 75

i am getting all the values from backend.

now our requirement is want to calculate amount for reno1,3,5 and row should be displayed as below:

recno rectype amount

1 autofare 100

3 busfare 25

5 carfare 75

amount 200 (here amount is not coming from backend.we need to add amount for recno 1,3 ,5 and iot should be displayed like that)

2 airfare 50

4 railfare 10

amount 60

please suggest how to proceed on this?

Regards,

Anitha

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

thanks

monalisa_biswal
Contributor
0 Kudos

hi Anitha,

you have to create a separate value node for storing original elements and their subtotals in the order you want them in the table.

For showing totals you can use cell variant in the table to give a different look and feel for the subtotal row.

Add another attribute in the value node for storing the variant name. bind this attribute to selected cell variant of table column.

int subtotal =0;
for(int i =0;i < size;i++)
{
IPrivate<view>NodeElement dataElement = dataNode.getDataElementAt(i);
IPrivate<view>NodeElement tablelement = wdContext.node<table>().createElement();
wdCopyService.copycorresponding(dataElement, tableElement);
//set cell variant to blank for original rows
tableelement.setSelectedVariant("");
 wdContext.node<table>().addElement(tablelement);

//Calculate subtotals and add them in another valuenode
subtotal = subtotal + dataElement.getAmt();
if(i ==3)// give condition at which you need to add subtotal row.
{
IPrivate<view>NodeElement subtotalelement = wdContext.node<table>().createElement();
subtotalelement.setSubtotal(subtotal);
//set cell variant for subtotal row
subtotalelementsetSelectedVariant("subtotal");
 wdContext.node<table>().addElement(tsubtotalelement);
subtotal =0; //reset subtotal 
}
}

hope this helps!

Monalisa

Former Member
0 Kudos

Hi,

My suggestion is dont bind the model node directly to table.

Instead of that bind the one value node to the table.

And everytime after model execution populate the data from model node to the value node.

After population of data. Add one more row (element) to that node as below.

int totalValue=0;

for(int i=0;i<wdContext.nodeModelNode.size();i++)

{

IprivateTestCompController.IValueNodeElement element=wdContext.createValueNodeElement();

element.setRecNo(wdCotnext.nodeModelNode().getModleNodeElementAt(i).getRecNo());

element.setRecAmount(wdCotnext.nodeModelNode().getModleNodeElementAt(i).getRecAmount());

totalValue+=wdCotnext.nodeModelNode().getModleNodeElementAt(i).getRecAmount();

-


-


-


wdContext.nodeValueNode().addElement(element);

}

IprivateTestCompController.IValueNodeElement element=wdContext.createValueNodeElement();

element.setRecAmount(totalValue);

Regards,

Charan

Former Member
0 Kudos

Hi,

In the same node which you have binded to the table, create two more calcuated attribtues

How to create calculated attribtues - Create one attribute and change the "Calculated" property of that attribute to true.

Now WebDynpro tool will generate one getter and one setter method to that attribue.

In the getter method of that attribute add the remaining columns values as below and return the calcualted value:

getFirstTotal(ITableNodeElement element)
{
//For example if the calcuated attribute is "FirstTotal" of type integer and
//alll the remaining attribtues are also of type integer then
return element.getRecNo1()+element.getRecNo2()+element.getRecNo3();
}

Regards,

Charan

Former Member
0 Kudos

Hi,

thanks for ur immediate reply.

we can able to calculate the amount, but we want to display that amount in the table as an additional row.

First in our table we have 4 columns, one of the column is amount.

After retrieving every values from the backend, there many rows will be displaying in the table .

End of these rows , one row must be added for displaying the total amounts. so this last row will have only 2 columns.

Could you please guide me how to add an additional row to display the calculated amount.

Regards,

Anitha