KoolReport's Forum

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

Only getting one line of data in CSV export #1675

Closed Paul S opened this topic on on Oct 20, 2020 - 2 comments

Paul S commented on Oct 20, 2020

I'm running into a very strange issue. I'm trying to run a CSV type report via array and the problem I'm having is I'm only getting my column header plus one row of data (there should be 9 rows of data). Interestingly enough, if I exclude my column header row, I get two rows of data so it's like there's a hard stop at two lines written to the CSV.

Here is my report class:

class HistoryReport extends \koolreport\KoolReport {

use \koolreport\excel\CSVExportable;

public function settings()
{
    return array(
        "dataSources"=>array(
            "report_data"=>array(
                "class"=>'\koolreport\datasources\ArrayDataSource',
                "data"=>$this->params["data"],
                "dataFormat"=>"table",
            )
        )
    );
}

function setup()
{

    $this->src('report_data')
        ->pipe(new Group(array(
            "RequestDate"=>"Request Date",
            "RequestedBy"=>"Requested By",
            "Amount"=>"Amount",
            "censored"=>"censored",
            "censored2"=>"censored2",
            "censored3"=>"censored3"
        )))
        ->pipe($this->dataStore('history'));
}

}

And here is the code that runs my report:

    $requests = get_requests();
    if(is_array($requests)) {
        $arr = [];
        array_push($arr,['Request Date','Requested By','Amount','censored','censored2','censored3']);
        foreach($requests as $request) {

            array_push($arr,[ $request['company_req_stamp'], $request['company_req_user'], $request['company_req_amount'], $request['company_censored'], $request['acct_inst'], $request['status_id']]);
        }

        $report = new HistoryReport(array(
            "data"=>$arr
        ));
        $report->run()->exportToCSV()->toBrowser('RequestHistory.csv');
        return;

    }

Does anyone possibly have any idea why I'm not seeing my header plus all 9 test records? I can verify that $arr (above) does have 9 elements in it after my loop is done.

Thanks in advance!

David Winterburn commented on Oct 21, 2020

Hi Paul,

Please try to remove the Group process and see what happens:

        $this->src('report_data')
        ->pipe($this->dataStore('history'));
Paul S commented on Oct 21, 2020

David, thank you!! That did it. I'm very new to KoolReport and I based that on an example I found. Removing those group lines and leaving just the two you showed fixed the problem.

Paul

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
None yet

None