KoolReport's Forum

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

How to use two dataStore in single table. #381

Open Sourabh Jain opened this topic on on Jul 19, 2018 - 8 comments

Sourabh Jain commented on Jul 19, 2018
public function setup()
    {
        $this->src('rp')
        ->query("SELECT annotation_type FROM tbl_user_annotation_activity")
        ->pipe(new Filter(array(
            array("annotation_type","!=","bookmark")
        )))
        ->pipe(new Group(array(
            "count"=>"annotation_id"
        )))
        ->pipe($this->dataStore('rp'));
        
        
        $this->src('rp')
        ->query("SELECT master_user_activity_id FROM tbl_user_enrichment_activity")
        ->pipe(new Group(array(
            "count"=>"master_user_activity_id"
        )))
        ->pipe($this->dataStore('rp1'));
}
Table::create(array(
    "dataStore"=>$this->dataStore('rp'),
        "columns"=>array(
            "annotation_id"=>array(
                "label"=>"Total Annotations Created",
            )
        ),
    "cssClass"=>array(
        "table"=>"table table-hover table-bordered"
    )
));
Table::create(array(
    "dataStore"=>$this->dataStore('rp1'),
        "columns"=>array(
            "master_user_activity_id"=>array(
                "label"=>"Total Enrichment Views"
            )
        ),
    "cssClass"=>array(
        "table"=>"table table-hover table-bordered" two
    )
));

I want to show the above data in a single table.

KoolReport commented on Jul 19, 2018

Use may use a single JOIN query to select both data at once and display in a single table

Sourabh Jain commented on Jul 19, 2018

I have nothing common in both tables.

KoolReport commented on Jul 19, 2018

Please let me how do you want to show in a single table?

Sourabh Jain commented on Jul 19, 2018

I have tried below approach too -

Same dataStore - public function setup()

{
    $this->src('rp')
    ->query("SELECT annotation_type FROM tbl_user_annotation_activity")
    ->pipe(new Filter(array(
        array("annotation_type","!=","bookmark")
    )))
    ->pipe(new Group(array(
        "count"=>"annotation_id"
    )))
    ->pipe($this->dataStore('annotation'));
    
    $this->src('rp')
    ->query("SELECT master_user_activity_id FROM tbl_user_enrichment_activity")
    ->pipe(new Group(array(
        "count"=>"master_user_activity_id"
    )))
    ->pipe($this->dataStore('annotation'));

    
}

Table::create(array(

"dataStore"=>$this->dataStore('annotation'),
    "columns"=>array(
        "annotation_id"=>array(
            "label"=>"Total Annotations Created",
        ),
        "master_user_activity_id"=>array(
            "label"=>"Total Enrichment Views"
        )
    ),
"cssClass"=>array(
    "table"=>"table table-hover table-bordered"
)

));

But problem is that it is showing 0 in the 1st row and then the correct value in the second row. Please see the attached image.

Sourabh Jain commented on Jul 19, 2018

I want to show data from two different dataStore in single table or chart or graph. For eg -

Table::create(array(
    "dataStore"=>$this->dataStore('annotation'),
        "columns"=>array(
            "annotation_id"=>array(
                "label"=>"Total Annotations Created", // This is from annotation dataStore
            ),
            "master_user_activity_id"=>array(
                "label"=>"Total Enrichment Views" // This is from another dataStore
            )
        ),
    "cssClass"=>array(
        "table"=>"table table-hover table-bordered"
    )
));
Sourabh Jain commented on Jul 24, 2018

Any update?

KoolReport commented on Jul 24, 2018

I suggest you to do get the raw data from both dataStores then you can merge them in the way you want, later you put the resulted array into table to display:

$rp = $this->dataStore("rp")->data();
$rp1 = $this->dataStore("rp1")->data();

Now you have $rp and $rp1 in form of array, each element is array is actually an array represent the row of table.

You can read and merge them into single $result array

Latter, you can display the $result like this:

Table::create(array(
    "dataSource"=>$result,
))

Hope that helps. Let me know if you have further question.

Sourabh Jain commented on Jul 24, 2018

Thanks. It works

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
solved

None