Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
Do you use the inputs package? if you use it, it is a little easier but it is fine if you have build your own selected date. I guess you make a form in the view of report and have selected date control over there, when you submit the form then you will receive the selected date from $_POST What you will do is that, if the button Export to Excel is hit ( supposed you have it) then at the index.php, instead of $report->run()->render();
you will called $report->run()->exportToExcel()->toBrowser("myreport.xlsx");
. Please have a look at our Export package documentation for more information.
Please let us know if you need further assistance.
Yes, i'm using input package.
here, is my sample code
<?php
use \koolreport\inputs\DateRangePicker;
use \koolreport\datagrid\DataTables;
?>
<div class="text-center">
<h1>Request Log Report</h1>
</div>
<div>
<form method="post">
<div class="row">
<div class="col-md-3 form-group">
<?php
DateRangePicker::create(array(
"name"=>"requestLogDateRange",
));
?>
</div>
<div class="col-md-3 form-group">
<button class="btn btn-primary">
<i class="fa fa-bar-chart"></i> Preview
</button>
</div>
<?php
if($this->dataStore("request_log_report_data")->countData()>0) {
?>
<div class="col-md-6 form-group">
<a href="exportPdf.php" class="btn btn-primary pull-right" style="margin-left: 10px;">Download PDF</a>
<a href="exportExcel.php" class="btn btn-primary pull-right" style="margin-left: 10px;">Download Excel</a>
<a href="exportCsv.php" class="btn btn-primary pull-right">Download Csv</a>
</div>
<?php } ?>
</div>
</form>
<hr/>
<?php
if($this->dataStore("request_log_report_data")->countData()>0)
{
DataTables::create(array(
"dataStore"=>$this->dataStore("request_log_report_data"),
"columns"=>array(
"Method"=>array(
"label"=>"Method"
),
"URI"=>array(
"label"=>"URI"
),
"Created By"=>array(
"label"=>"Created By"
),
"Created"=>array(
"label"=>"Created"
),
),
"options"=>array(
"searching"=>true,
"paging"=>true,
"orders"=>array(
array(3,"desc"), //Sort by Created column desc
),
"colReorder"=>true,
"fixedHeader"=>true,
"pageLength" => 25,
)
));
} else {
?>
<div class="alert alert-warning">
<i class="glyphicon glyphicon-info-sign"></i> Data is not available
</div>
<?php } ?>
</div>
function setup()
{
$this->src('loanencounter')
->query("
SELECT
request_logs.method,
request_logs.uri,
request_logs.created_at,
users.first_name,
users.last_name
FROM
request_logs
LEFT JOIN users ON request_logs.created_by = users.id
WHERE
request_logs.created_at >= :fromDate
AND
request_logs.created_at <= :toDate
")
->params(array(
":fromDate"=>$this->params["requestLogDateRange"][0],
":toDate"=>$this->params["requestLogDateRange"][1]
))
->pipe(new Custom(function($row){
$row["first_name"] = $row["first_name"]." ".$row["last_name"];
return $row;
}))
->pipe(new ColumnRename(array(
"method"=>"Method",
"uri"=>"URI",
"first_name"=>"Created By",
"created_at"=>"Created",
)))
->pipe(new RemoveColumn(array(
"last_name"
)))
->pipe(new Sort(array(
"Created"=>"desc"
)))
->pipe($this->dataStore('request_log_report_data'));
}
i'm using seprate php file for export.
<?php
require_once "RequestLog.php";
$report = new RequestLog;
$report->run()->exportToExcel()->toBrowser("RequestLog.csv");
I can access parameter in setup(). but whenever i'm changing daterange in view. it's not change in export. here, is my defaultParamValues() protected function defaultParamValues()
{
$toDate = date("Y-m-d H:i:s");
$fromDate = date('Y-m-d',strtotime("-6 days"));
return array(
"requestLogDateRange"=>array($fromDate, $toDate)
);
}
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo