Jump to content
We've recently updated our Privacy Statement, available here ×

How to dynamically add column in a simple table


psentosa

Recommended Posts

Hi all,

I'd like to print a report (Shoe order for a certain model) which have the following form:

Model A

Shop name                            Order

Shop1                                     33          35       37       38

                                                  2           2          5         9

Shop2                                     31           32        38       42     44

                                                  1            2          3         5        6

 

As you can, each records contains following information:

1. The name of the shop that give the orders

2. Amount of the shoes pair for each ordered size

There are so many different sizes, and any shop should order shoes in certain sizes that they currently need; so the number of the columns for the table in the "Order"-Column should be dynamic.

Any advices on how to create the table?

FYI, I use java data source for the report, so in this case I will have a data model such as:

 

public class OrderDataEntry {

String shopName;

/** the key of the map is the size, and the value is the amount*

Map<Integer, Integer> shoeOrders;

}
 

Thanks in advance

 




Post Edited by psentosa at 04/29/2010 14:45
Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

See demo/samples/crosstabs in the JR distribution to get an idea on how crosstabs work.

As I was saying, in order to use a crosstab you'd have to change your data source to produce records like these:

Shop1, 33, 2

Shop1, 35, 2

Shop1, 37, 5

Shop2, 31, 1

Shop2, 32, 2

...

If you can do that, you'd then define a crosstab that has the shop as row group, the size as column group and the count as measure.

Regards,

Lucian

Link to comment
Share on other sites

Hi Lucian,

 

again, thanks a lot for your reply.

One last question, actually the records are a little bit more:

 

Model A

Shop name                            Order                                                             Delivery                            Price

Shop1                                     33          35       37       38                             10.11.2012                       100

                                                  2           2          5         9

Shop2                                     31           32        38       42     44                 12.10.2012                        200

                                                  1            2          3         5        6

 

So, as you can see, actually there are some more columns; using "your model",

is it ok to have the records like this:

Shop1, 33, 2, 10.11.2012, 100

Shop1, 35, 2, 10.11.2012, 100

Shop1, 37, 5, 10.11.2012, 100

Shop2, 31, 1, 12.10.2012, 200

Shop2, 32, 2, 12.10.2010, 200

And as there are some columns now, how to decide which 2 are the column groups and how to determine the row group?

Many many thanks!

 

Regards

Link to comment
Share on other sites

That adds some complexity because the case diverges from what crosstabs were meant to do.

But you can still do it by adding the delivery and price values as measures (use calculation="Nothing" for them), and displaying them in the row total cell.

I know this is getting a liitle too complex, but I don't see other feasible solutions.  You could a horizontal list to display the size order values, but that doesn't allow you to push to the right the delivery and price text fields.

Regards,

Lucian

Link to comment
Share on other sites

  • 2 weeks later...

Hi Lucian,

thanks for your hints.

I managed to create the table I want.

Just a further question, that you could answer if you have some spare time :) :

Actually there are some more columns beside delivery and price, two of which are related with the price:

 unit price      total price

 

unit price is a fix value, while total price is based on the sum of the number or ordered shoes, so it would look like:

                                            Amount               Unit Price                          Total price

33     35      37  39

2       2          2     2                 8                           15                                           120

I still manage to get the amount value right (by using calculation type "Sum" on the number measure, but is there any possibilty to automaticall calculate the total price?

Thanks and have a nice weekend!

 

Regards

Link to comment
Share on other sites

I've been trying to create a dynamically sized table just like yours for a while now, would you mind posting how you got it to work?

 

In the past I've only been able to solve it by brute forcing it and creating different column headers / detail frames for each condition... not very efficient.

Link to comment
Share on other sites

Hi Shaded..

what I did is exactly what Lucian has recommended:

using crosstabs, and define your dynamic columns as column groups..

further I set the rest of the columns which are static (i.e only 1 column) as measures...

try to play with the crosstabs a bit and you'll get what I mean

 

Cheers

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...