我有一个数据表,其中包含从数据库中检索到的数据。当我在搜索文本框中输入一些关键字时(搜索文本框是由数据表生成的),表格的结果会发生变化。这很好。但是,当我单击导出到 csv 或 pdf 时,将从数据库而不是数据表中检索 csv 或 pdf 格式的结果。
如何使用laravel导出基于datatables插件的csv/pdf?
//数据表插件
<link href="plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<script src="plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>
//PHP
public function sales_csv(){
// columns
$arrSelectFields = array(
-- columns --
);
// query
-- sql queries --
// passing the columns which I want from the result set. Useful when we have not selected required fields
$arrColumns = $arrSelectFields;
// define the first row which will come as the first row in the csv
$arrFirstRow = $arrSelectFields;
// building the options array
$options = array(
'columns' => $arrColumns,
'firstRow' => $arrFirstRow,
);
// creating the Files object from the Utility package.
$Files = new Files;
return $Files->convertToReportsSalesCSV($query, $options);
}
最佳答案
我可能会将关键字发布到我的服务器并再次运行 sql 查询来过滤这些结果,然后创建 csv/pdf
关于php - 基于数据表 Laravel 4 导出 CSV 或 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32173798/