我有一个datatables,其中包含从数据库检索到的数据.当我在搜索文本框(搜索文本框由datatables生成)中输入一些关键字时,表的结果将发生变化.这很好.但当我单击export to 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);
}