KoolReport's Forum

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

Create Label Sequence Number and Captured in DataStore as a Column #2443

Closed hsw opened this topic on on Nov 19, 2021 - 4 comments

hsw commented on Nov 19, 2021

Hi,

I am creating a report with 2 Tables. I need to assign Label for each row in the Tables. Instead of assigning/hardcoding the Labels in the Report.view.php, I want the Labels to be captured in DataStore as a column.

Table A:
P1    EOS
P2    UJE
P3    UBK
P4    KKD

Table B:
P5    IEJ
P6    LJW
P7    KJN
P8    YTD

I tried doing this way for Table A, but the counter only increment once.

$ctr= 0;

$this->src('packages')
->pipe(new Filter(array( ....)))
->pipe(new Sort(array( ....)))
->pipe(new Limit(array(4)))

->pipe(new CalculatedColumn(array(
      "Counter"=>function($row) use($ctr) 
            { return $ctr;  }
      "Label"=>"{Counter}+1",
)))

->pipe(new Custom(function($row){
   $row["Label"]=>"P".$row["Label"];
...

Hope someone can share how this can be done correctly. Thank you

Sebastian Morales commented on Nov 19, 2021

Pls try this:

$ctr = 0;
...
->pipe(new CalculatedColumn(array(
      "Counter"=>function($row) use(& $ctr) // pass $ctr by reference, not value
            {
                $ctr++;
                return $ctr - 1;  
            }
      "Label"=>"{Counter}+1",
)))

Let us know if it works for your case. Tks,

hsw commented on Nov 19, 2021

Thanks Sebastian. It works.

hsw commented on Nov 19, 2021

Hi,

I further process and encountered a strange problem.

I created 2 dataStores from the same datasource. The Filter criteria is the same for both dataStores. The difference is Transpose() process is used for the dataStore A while not used for dataStore B.

$ctr = 0;
...
->pipe(new CalculatedColumn(array(
      "Counter"=>function($row) use(& $ctr) // pass $ctr by reference, not value
            {
                $ctr++;
                return $ctr - 1;  
            }
      "Label"=>"{Counter}+1",
)))
....
->pipe(new Custom(function($row) {
   $row["Label"]=>$row["Other Field"]." P".$row["Label"];
      return $row; }
->pipe(new Transpose())   // only for dataStore A

->pipe($this->dataStore('dataStoreA'));

I can see the Label data output correctly in the Table from dataStore A. It shows as XXX P1, YYY P2, SSS P3, ZZZ P4 in a row. With Transpose columns becomes rows.

However, for the Table that is output from dataStore B, the Label column is empty. But when I commented off the Custom process. The Label column is able to display 1, 2, 3, 4.

Appreciate if someone can help me see what's the problem. Thank you.

hsw commented on Nov 23, 2021

Hi Can ignore my previous post. Managed to resolve.

Thank you.

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
solved

None