cancel
Showing results for 
Search instead for 
Did you mean: 

Add similar rows of table

Former Member
0 Kudos

Hi ,

I have requirement like this,

From my back end , I am retrieving values and displaying it in table.

My problem is , i want to add the percentage of similar rows and display only once in the table.

Consider this data is in back end,

Percentage Descr

10 d1

20 d2

30 d1

15 d1

10 d2

25 d3

My output should be as,

Percentage Descr,

55 d1

30 d2

25 d3

Could you please suggest me some steps to get my required output.

Regards,

Anitha

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Instead of creating the context elements directly from the query result, you could first build a map from descriptions to accumulated percentage values and create the context elements from that map. Something like


Map<String,Integer> percentageByDesc = new TreeMap<String,Integer>();
foreach (record : result)
{
  Integer value = percentageByDesc.get(record.description);
  if (value == null)
    percentageByDesc.put(record.description, record.percentage);
  else
    percentageByDesc.put(record.description, Integer.valueOf(value.intValue() + record.percentage));
} 
foreach (Map.Entry<String,Integer> entry : percentageByDesc)
{
  I<Node>Element e = wdContext.node<Node>().createAndAdd<Node>Element();
  e.setDescription(entry.getKey());
  e.setPercentage(entry.getValue());
} 

Armin

Former Member
0 Kudos

Hi,

For this you need to create another node of type value node and bind your displayable table to it.

Have a workaround like the following steps

1) Create a Arraylist and append the data from node to the arraylist

2) Sort the Arraylist such that you can see all the simillar Descr in the consequent rows.

3) iterate a loop and in the loop check whether the two or three consequtive rows are simillar, then add the

percentage values and bind the value to a newly created value node.

Regards

Raghu