KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

New Page base on one colum of data array #1138

Closed Fabio da Silva opened this topic on on Oct 25, 2019 - 2 comments

Fabio da Silva commented on Oct 25, 2019

Hi,

I would like to request assistance in a situation we are unable to identify in your documentation, and that situation will be required for some reports we use. This refers to the generation of a "new page" as the query data varies.

Consider the following example data:

"name";"class";"grade";"year"

"Karl";"Mathematics";"1";"2018"
"Karl";"English";"2";"2019"
"Fabio";"Mathematics";"1";"2018"
"Fabio";"Portuguese";"2";"2019"

In the report view file, it will have a layout similar to:

<page header>

Hi {data.name}, below your data:

| Class        | Grade        | Year        | 
| {data.class} | {data.grade} | {data.year} | 

Thank you.

<page footer>

We need to generate this "view" for each of data, in exchange for {data.name}. In the example above there will be the structure shown above for the "Karl" data, and after this a second structure for the "Fabio" data. Print Example:

<page header>

Hi Karl, below your data:

| Class       | Grade | Year |
| Mathematics | 1     | 2018 |
| English     | 2     | 2019 |

Thank you.

<page footer>

<page header>

Hi Fabio, below your data:

| Class       | Grade | Year |
| Mathematics | 1     | 2018 |
| Portuguese  | 2     | 2019 |

Thank you.

<page footer>

Ideally in a print or PDF, two pages would be generated. Is there anything standard in your tool or package that can handle this kind of generation?

Thank you for your attention.

KoolReport commented on Oct 28, 2019

Here is direction for you:

  1. From your data, you need to use the Group to get distinct name of student, so from the list, you should get dataStore "students" with 2 rows "Karl" and "Fabio".
  2. And from your data, you pipe to a dataStore "all" to keep all data.

Now in the view, you have 2 dataStores, the first one is "students" which keeps distinct name of student, and "all" which keeps all data like your above data.

You will loop through distinct student name, filter "all" data by student name like this:

foreach($this->dataStore("students") as $student)
{
    $student_data = $this->dataStore("all")->filter("name","=",$student["name"]);
    //Now you can display the information of each student:

    Table::create(array(
        "dataSource"=>$student_data,
        "columns"=>array("class","grade","year")
    ));
}

For the header and footer of PDF, please have a look at our Export package documentation. We also have documentation to add the page break.

Fabio da Silva commented on Oct 29, 2019

Hi,

Thanks for the reply, with this information we were able to configure the report. Only one correction, there is a missing ")" in the foreach example line.

Thank you for your help!

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None