0

As i understand it, we can group the dataset by column in jasper report. But this requires the grouping process to be done by jasper report itself.

For example, with these item purchased dataset:

1. Peanut Butter, qty is 100, priced at 1000
2. Peanut Butter, qty is 10, priced at 1200
3. Blueberry Jam, qty is 20, priced at 3000

If i were to tell jasper to group by item name, and then i pass my dataset to jasper as a list of map objects like:

[
  { name: 'Peanut Butter', qty: 100,price: 1000},
  { name: 'Peanut Butter', qty: 10,price: 1200},
  { name: 'Blueberry Jam', qty: 20,price: 3000}
]

And the rendering output of jasper would become:

Peanut Butter
  100    1000
  10     1200
Blueberry Jam
  20     3000

What if i want to do the grouping process in the db, even if it means doing many queries, and pass the already-grouped-datasets (including nested grouping) to jasper report to fill and render it as 'grouped' column ?

So my query and grouping in the db will procuce a dataset that would look something like a map, with the key is the 'grouped' column[s], and the value is the Map of the records, something resembling this:

{
  Peanut Butter: [
    { qty: 100,price: 1000},
    { qty: 10,price: 1200}
  ],
  Blueberry Jam: [
    { qty: 20,price: 3000},
  ]
}

This dataset is then passed 'somehow' to the jasper report engine, and also telling jasper to group by item. My expectation of jasper would render the output the same way, but it 'skips' grouping the data, and just use the 'grouped' dataset i passed.

This way i can make use of my db to do the querying and grouping, yet still preserve the group rendering in the report output. With jasper not sorting, grouping data in-memory, i also expect the report filling process to be faster.

I have taken a peek at JRDataSource, but seems like i cannot override the data source impl for the 'grouped' data, or somehow passing the already-grouped-data, so im wondering whether this is possible to achieve.

Bertie
  • 17,277
  • 45
  • 129
  • 182
  • 1
    Your question is unclear – Alex K Jul 26 '16 at 11:30
  • Sorry guys for the midnight posting syndrom. I've edited my question. Hopefuly it's clearer now. – Bertie Jul 27 '16 at 01:59
  • 1
    To me it seems like you are looking for something similar to this http://stackoverflow.com/questions/34639662/how-to-design-report-with-tabular-format/34653695#34653695 (hence using subdatasource with sub report or (table list component) , however if this is faster (needs to be tested), better design (opinion based). I would stick to flat query and use normal jasper-report groups. – Petter Friberg Jul 27 '16 at 08:02
  • 1
    Report groups are just a way to render some content and trigger some events when the value of a field (or an expression) changes from one record to he next. Grouping per se does not involve sorting or other expensive operations; if the data is not already sorted you'd have repeating groups. Therefore if you group the data by yourself, you can flatten it (repeat the group fields on each record) and create report groups on the fields without defining any sort fields. – dada67 Jul 27 '16 at 14:55
  • Thanks guys. I'll do some measuring and post it here in the future. – Bertie Jul 28 '16 at 10:17

0 Answers0