I have a datatables which contains the data retrieved from database. When I enter some keywords into search textbox (the search textbox is generated by datatables), the result of the table will be changes. This is good. But when I click export to csv or pdf, the result in csv or pdf will be retrieved from database instead of datatables.
How to export to csv/pdf based on the datatables plugin using 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);
}
I would probably post the keyword to my server and run the sql query again filtering those results and then create the csv/pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With