У меня есть datatables, который содержит данные, полученные из базы данных. Когда я ввожу некоторые ключевые слова в текстовое поле поиска (текстовое поле поиска генерируется с помощью datatables), результат таблицы будет изменен. Это хорошо. Но когда я нажимаю export to csv или pdf, результат в csv или pdf будет извлекаться из базы данных вместо datatables.
Как экспортировать в csv/pdf на основе плагина datatables с использованием laravel?
//datatable plugins
<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);
}